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
and15
: Before the menu dialog gets the control, thenext
andprevious
actions are disabled, by using thesetup_dialog
function. - Lines
35
thru38
: Thesetup_dialog
function is in charge of action activation or de-activation. Thedlg
parameter is the dialog object, andcan_nav
is the boolean value that indicates if navigation actions can be enabled. - Lines
17
and18
: The can_nav boolean variable is created in the local scope, from the returned value of thequery_cust
function. According to this boolean value, thenext
andprevious
actions are enabled or disabled. - Lines
19
thru22
: If the query was successful thenext
andprevious
actions are enabled and will trigger the row fetch. - Line
25
and26
: Theclose
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, theEXIT MENU
, will be taken.