Example: custmain.4gl

Calls to the ui.Dialog.setActionActive method have been added to custmain.4gl to disable and enable menu actions appropriately to give the user visual cues. An additional ON ACTION close statement exits the menu if the user selects the "X" in the upper right corner of the interface.

Module custmain.4gl:
  1 IMPORT FGL custquery
  2 
  3 MAIN
  4 
  5   DEFER INTERRUPT
  6 
  7   CONNECT TO "custdemo"
  8 
  9   CLOSE WINDOW SCREEN
 10   OPEN WINDOW w1 WITH FORM "custform"
 11      ATTRIBUTES(TEXT="Customer")
 12 
 13   MENU "Customer"
 14     BEFORE MENU
 15       CALL setup_dialog(DIALOG,FALSE)
 16     ON ACTION query ATTRIBUTES(COMMENT="Search for customers")
 17       VAR can_nav = custquery.query_cust()
 18       CALL setup_dialog(DIALOG,can_nav)
 19     ON ACTION next
 20       CALL custquery.fetch_rel_cust(1)
 21     ON ACTION previous
 22       CALL custquery.fetch_rel_cust(-1)
 23     ON ACTION quit
 24       EXIT MENU
 25     ON ACTION close
 26       EXIT MENU
 27   END MENU
 28 
 29   CLOSE WINDOW w1
 30 
 31   DISCONNECT CURRENT
 32 
 33 END MAIN
 34 
 35 PRIVATE FUNCTION setup_dialog(dlg ui.Dialog, can_nav BOOLEAN) RETURNS ()
 36   CALL dlg.setActionActive("next",can_nav)
 37   CALL dlg.setActionActive("previous",can_nav)
 38 END FUNCTION
Note:
  • Lines 14 and 15: Before the menu dialog gets the control, the next and previous actions are disabled, by using the setup_dialog function.
  • Lines 35 thru 38: The setup_dialog function is in charge of action activation or de-activation. The dlg parameter is the dialog object, and can_nav is the boolean value that indicates if navigation actions can be enabled.
  • Lines 17 and 18: The can_nav boolean variable is created in the local scope, from the returned value of the query_cust function. According to this boolean value, the next and previous actions are enabled or disabled.
  • Lines 19 thru 22: If the query was successful the next and previous actions are enabled and will trigger the row fetch.
  • Line 25 and 26: The close action is included in the menu, although an action view won't display on the form. If the user clicks the "X" in the top right of the window, the EXIT MENU, will be taken.