Dynamic Menus And Parameters?

jdpjamesp

ProgressTalk.com Moderator
Staff member
Having a complete mental block. I'm looking at moving our static menus into the DB and have come across an issue.
Code:
CREATE MENU-ITEM lv-item-ptr IN WIDGET-POOL "StubMenu"
     ASSIGN PARENT = lv-sub3-ptr
     LABEL = "Update Billing Record Current Month Number..."
     TRIGGERS:
     ON CHOOSE PERSISTENT
       RUN DataDefinitionUpload IN THIS-PROCEDURE (INPUT "lv-CallingHandle=" + STRING(THIS-PROCEDURE:HANDLE) + "|lv-Mode=IMPORT|lv-ProgramFileName=" + THIS-PROCEDURE:FILE-NAME + "|lv-ParamList=lv-FormatName#EQUALS#Update Billing Current Month No.").
     END TRIGGERS.

CREATE MENU-ITEM lv-item-ptr IN WIDGET-POOL "StubMenu"
     ASSIGN PARENT = lv-sub3-ptr
     LABEL = "Update Billing Record Purchase Order Number..."
     TRIGGERS:
     ON CHOOSE PERSISTENT
       RUN DataDefinitionUpload IN THIS-PROCEDURE (INPUT "lv-CallingHandle=" + STRING(THIS-PROCEDURE:HANDLE) + "|lv-Mode=IMPORT|lv-ProgramFileName=" + THIS-PROCEDURE:FILE-NAME + "|lv-ParamList=lv-FormatName#EQUALS#Update Billing Record PO Number").
     END TRIGGERS.

CREATE MENU-ITEM lv-item-ptr IN WIDGET-POOL "StubMenu"
     ASSIGN PARENT = lv-sub3-ptr
     LABEL = "Update Costs For Split Gas Meter..."
     TRIGGERS:
     ON CHOOSE PERSISTENT
       RUN DataDefinitionUpload IN THIS-PROCEDURE (INPUT "lv-CallingHandle=" + STRING(THIS-PROCEDURE:HANDLE) + "|lv-Mode=IMPORT|lv-ProgramFileName=" + THIS-PROCEDURE:FILE-NAME + "|lv-ParamList=lv-FormatName#EQUALS#Update Costs For Split Gas Meter").
     END TRIGGERS.

Apart from the fact that this is horrendous to read, is there a way of achieving this dynamically?

Code:
          CREATE MENU-ITEM lb-DBMenuItem.MenuItemHandle IN WIDGET-POOL "StubMenu"    
            ASSIGN 
            PARENT = tt-DBMenuItem.MenuItemHandle
            LABEL = lb-MenuItem.MitMenuItemDescId
            TRIGGERS:
              ON CHOOSE PERSISTENT RUN VALUE(lb-MenuItem.MitMenuCommand) IN THIS-PROCEDURE.
            END TRIGGERS.

That's what I'm doing with the calls that are simple procedure calls. Just not sure what to do with the ones that take params short of creating an internal procedure without params for each one.
 
Either

1. standardize your call interface from a menu - at most I would expect that you have one or two parameters to pass in - so you can create menu-items with 0, 1 or 2 parameters.

or

2. create a call object, add as many parameters as you need and invoke that
 
A call object would one or more generic programs that take a number of inputs that just turn around and call other procedures. How complicated this would be would depend on how many different variations you have of input and output parameters.

For the example you posted you could assign values to the PRIVATE-DATA. Something like this... (might have to change the handle on the run to SELF, not tested)


Code:
          CREATE MENU-ITEM lb-DBMenuItem.MenuItemHandle IN WIDGET-POOL "StubMenu"   
            ASSIGN
            PARENT = tt-DBMenuItem.MenuItemHandle
            LABEL = lb-MenuItem.MitMenuItemDescId
            PRIVATE-DATA = "PROGRAM_TO_RUN" + CHR(6) + "input parameter value"
            TRIGGERS:
              ON CHOOSE PERSISTENT RUN 
                             VALUE(ENTRY(1,lb-DBMenuItem.MenuItemHandle:PRIVATE-DATA,CHR(6))) IN THIS-PROCEDURE
                              (INPUT ENTRY(2,lb-DBMenuItem.MenuItemHandle:PRIVATE-DATA,CHR(6))).
            END TRIGGERS.
 
Cringer, have you looked at menucre.p and the menuex1-3.p's in the samples folder as that shows how to create dynamic menus from menu data contained in a single string. A bit of adjustment required to menucre.p to incorporate the extra requirements as per TheMadDBA's post but hopefully it does the job.
 
See the 'call object handle' in the help file, here's a simple internal call to get you started.

Code:
define variable hc as handle no-undo.

create call hc.
hc:call-name = "myproc".
hc:num-parameters = 1.
hc:set-parameter( 1, "character", "input", "cringer" ).
hc:invoke().

procedure myproc:
   define input parameter i_c as character no-undo.

   message 'hello' i_c view-as alert-box.

end procedure.
 
Back
Top