FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Items of a popup menu
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Items of a popup menu
Posted: Wed Nov 06, 2013 12:36 PM
On a dialog a I have a xbrowse with buttons at the bottom






ON a button I have a menu popup

I create this menu popup from a dbf

each items of menu have an action for the oBrw of the Invoice

I Put the menu popup into rbtn button at the bottom of the oBrw (xbrowse)

the problem is the baction is processed before to open the dialog and the obrw

but I wish not process the bation before but when the final user select the item from menu

How i can make it ?

Code (fw): Select all Collapse
Function MenuVociNote(oBrw,nInvoice)
   Local avocinote :={}

  SELECT NV
     while ! NV->(Eof())
       Aadd(avocinote, NV->NVDESCR)
        NV->(DbSkip())
     enddo

 MENU oPopupNote POPUP   2010
    For i := 1 to Len(avocinote)
    bAction :=InserVoci(i, oBrw, nInvoice)
     MENUITEM RTrim(avocinote[i]) BLOCK bAction
   Next i
   MENUITEM "Personalizza "
   ENDMENU

   return oPopupNote



Function   InserVoci(n,oBrw,nInvoice)

   SELECT NV
   NV->(dbgoto(n))
     IF msgYesNo("Devo inserire questa voce"+ NV->NVDESCR)
             SELECT   PA
             PA->(DbAppend())
             Replace  PA->PAINVOICE  With   nInvoice
             Replace  PA->PADESC With  NV->NVDESCR
             PA->(DbCommit())
         endif

  * oBrw:refresh()
  * oBrw:setfocus()
      */



Return NIL
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Items of a popup menu
Posted: Thu Nov 07, 2013 08:24 AM
here there 's a smal test to try

append on VOCINOTe.dbf some records


Code (fw): Select all Collapse
#Include "Fivewin.ch"
#include "xbrowse.ch"
#include "constant.ch"
#include "ribbon.ch"

  REQUEST DBFCDX
  REQUEST DBFFPT
  EXTERNAL ordkeyno, ordkeycount,ordcreate,ordkeygoto

Static avocinote

Function Invoice()
Local oFrmInvoice
Local oBrw
Local oFld
Local oBtn[3]


   //--------------------------------------------------------------//
   Local  nBottom   := 22
   Local  nRight    := 110
   Local nWidth :=  Max( nRight * DLG_CHARPIX_W, 180 )
   Local nHeight := nBottom * DLG_CHARPIX_H
   //--------------------------------------------------------------//





 avocinote :={}
 nInvoice :="1"
 cTitle_FrmInvoice:="Invoice"
 Create_Data()
 Open_data()


               //--------------------------------------------------------------//

                           SELECT PA
                         PA->(DbSetOrder(1))
                         PA->( OrdScope(0, { || alltrim((nInvoice)) }))
                         PA->( OrdScope(1, { || alltrim((nInvoice)) }) )
                         PA->(DbGoTop())
               //--------------------------------------------------------------//



 DEFINE DIALOG oFrmInvoice  TITLE cTitle_FrmInvoice     ;
 SIZE nWidth, nHeight   PIXEL



 @ 25, 3 FOLDER oFld OF oFrmInvoice SIZE 400, 100 PIXEL  ;
     PROMPT "Righe documento","Pagamento","Trasporto","Note","Provvigione","Indirizzi","Opzione"


  aBrowse     :=  { { "PAITEM",   i18n("Codice"),      nil,           50 }  ,;
                        { "PADESC",   i18n("Descrizione"), nil,          200 }  ,;
                        { "PAMEAS",   i18n("Misura"),      nil,           40 }  ,;
                        { "PAQTY",    i18n("Quantità"),    "9999",        60 }  ,;
                        { "PATAX",    i18n("Iva"),         "99",          40 }  ,;
                        { "PADESCONT",i18n("Sconto"),      '@ 999.99',    40 }  ,;
                        { "PAUNIT",   i18n("Unitario"),    '@ 99,999.99', 80 }  ,;
                        { "PATOTAL",  i18n("Totale"),      '@ 99,999.99', 80 }}

     @ 0, 0 XBROWSE oBrw       ;
      OF oFld:adialogs[1] DATASOURCE "PA" ;
      COLUMNS aBrowse CELL LINES NOBORDER FOOTERS  SIZE 400,80





                              oBrw:SetRDD()
                              oBrw:CreateFromCode()
                              oBrw:lFooter:=.t.
                              oBrw:MakeTotals()
                              oBrw:RefreshFooters()

                              @ 130,20 RBBTN oBtn[1] PROMPT "Inser Voces";
                                   MENU  MenuVociNote(oBrw,nInvoice) ;
                                   SIZE  100,10  OF oFrmInvoice POPUP

                               @ 130,160 RBBTN oBtn[2] PROMPT "Exit";
                                   SIZE  40,10  OF oFrmInvoice ACTION  oFrmInvoice:end()
     ACTIVATE DIALOG oFrmInvoice CENTER
     RETURN NIL

//--------------------------------------------------------------//


Function MenuVociNote(oBrw,nInvoice)
     SELECT NV
     while ! NV->(Eof())
       Aadd(avocinote, NV->NVDESCR)
        NV->(DbSkip())
     enddo

 MENU oPopupNote POPUP   2010
    For i := 1 to Len(avocinote)
    bAction :=InserVoci(i, oBrw, nInvoice)
     MENUITEM RTrim(avocinote[i]) //BLOCK bAction
   Next i
   MENUITEM "Personalizza "  Action Msginfo("Archive voces")
   ENDMENU

   return oPopupNote


//--------------------------------------------------------------//
Function   InserVoci(n,oBrw,nInvoice)

   SELECT NV
   NV->(dbgoto(n))
     IF msgYesNo("Devo inserire questa voce"+ NV->NVDESCR)
             SELECT   PA
             PA->(DbAppend())
             Replace  PA->PAINVOICE  With   nInvoice
             Replace  PA->PADESC With  NV->NVDESCR
             PA->(DbCommit())
         endif

  * oBrw:refresh()
  * oBrw:setfocus()
      */



Return NIL






//--------------------------------------------------------------//

Function Open_data()


   if ! Db_OpenNoIndex("Parts","PA")
      return nil
   endif

      INDEX ON PA->PAINVOICE  TAG PaInvoice  TO PARTS

 if ! Db_OpenNoIndex("VOCINOTE","NV")
      return nil
   endif

RETURN NIL

//--------------------------------------------------------------//



function Db_OpenNoIndex(cDbf,cAlias)
   if file( cDbf + ".dbf" )
      USE &(cDbf+".dbf")      ;
         ALIAS &(cAlias) NEW
   else
     MsgStop( i18n( "Non si è trovato l'archivio dei dati." ) + CRLF + ;
               i18N( "Per favore  controlla la configurazone") + CRLF + ;
                i18N( "e indicizza gli archivi dell'applicazione." ) )
      return .f.

   END if
   if NetErr()
     msgStop( i18n( "Errore nell'aprire un archivio" ) + CRLF + ;
              i18n( "Per favore caricare di nuovo l'applicazione." ) )
      DbCloseAll()
      return .f.
   endif
   return .t.

//--------------------------------------------------------------//


Function Create_Data()
         cDir:=cFilePath(GetModuleFileName(GetInstance()))


 //PARTS

         DbCreate(cDir+'PA', { {'PAITEM'    ,'C',010,000},;  // Codigo
                               {'PADESC'    ,'C',030,000},;  // description
                               {'PAMEAS'    ,'C',010,000},;  // measure
                               {'PAQTY'     ,'N',004,000},;  // quantity
                               {'PAUNIT'    ,'N',012,002},;  // Price unit
                               {'PATOTAL'   ,'N',012,002},;  // total
                               {'PAFLAG'    ,'C',001,000},;  // flag internal
                               {'PADESCONT' ,'N',005,002},;  // Descount
                               {'PATAX'     ,'C',002,000},;
                               {'PAIMPON'   ,'N',012,002},;  // total
                               {'PAINVOICE' ,'C',004,000}}, 'DBFCDX')  // Number of Invoice

      close all
      use &(cDir+'PA') new
      select PA
      if FILE(cDir+'Parts.DBF')
         delete file &(cdir+'Parts.cdx')
         append from &(cdir+'Parts')
         dbcommitall()
         close all
         delete file &(cdir+'Parts.dbf')
      endif
       close all
      rename &(cdir+'PA.dbf') to &(cdir+'Parts.dbf')

//--------------------------------------------------------------//

   DbCreate(cDir+'NV', {   {'NVDESCR'   ,'C',060,000}}, 'DBFCDX')

       close all
      use &(cDir+'NV') new
      select NV
      if FILE(cDir+'VOCINOTE.DBF')
         delete file &(cdir+'VOCINOTE.cdx')
         append from &(cdir+'VOCINOTE')
         dbcommitall()
         close all
         delete file &(cdir+'VOCINOTe.dbf')
      endif
       close all
      rename &(cdir+'NV.dbf') to &(cdir+'VOCINOTE.dbf')

//--------------------------------------------------------------//

 RETURN NIL
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Items of a popup menu
Posted: Thu Nov 07, 2013 06:17 PM

Silvio,

That is not what I would call a small test.

How about one with only a dialog, ribbonbar, button, and popup menu containing one item--no browse, no databases, etc.

Make it as small as possible to just show the problem. Eliminate every line that is not needed to show the problem.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Items of a popup menu
Posted: Fri Nov 08, 2013 12:35 PM

James I revolved with codeblock

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Items of a popup menu
Posted: Sat Nov 09, 2013 05:07 PM

Glad to hear it!

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Items of a popup menu
Posted: Sat Nov 09, 2013 05:23 PM
yes,
I saw if I make a codeblock to run another function it not process the baction of Menuitem
I don't Know Why...
on baction I put a function

bAction :=ApVoci(avocinote[i], oBrw, nInvoice)
MENUITEM RTrim(avocinote[i]) BLOCK bAction


on this function I put a codeblock

Function ApVoci(ctext, oBrw, nInvoice)
return { || InserVoci(ctext,oBrw,nInvoice)}

on third function I run the action I wish create

Don't ask me How I make this or How I found it because I don't Know :-)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion