Example: custmain.4gl
The MENU statement in the module custmain.4gl
is modified to call functions for appending, updating, and deleting the rows in the customer
table.
The custmain.4gl module:
1 IMPORT FGL custquery
2 IMPORT FGL custdata
3
4 MAIN
5 DEFINE curr_cust custdata.t_cust_num
6
7 DEFER INTERRUPT
8
9 CONNECT TO "custdemo"
10
11 CLOSE WINDOW SCREEN
12 OPEN WINDOW w1 WITH FORM "custform"
13 ATTRIBUTES(TEXT="Customer")
14
15 MENU "Customer"
16 BEFORE MENU
17 CALL setup_dialog(DIALOG,FALSE)
18 ON ACTION query ATTRIBUTES(COMMENT="Search for customers")
19 VAR can_nav = custquery.query_cust()
20 CALL setup_dialog(DIALOG,can_nav)
21 IF can_nav THEN
22 LET curr_cust = custquery.fetch_rel_cust(0)
23 END IF
24 ON ACTION first
25 LET curr_cust = custquery.fetch_rel_cust(0)
26 ON ACTION next
27 LET curr_cust = custquery.fetch_rel_cust(1)
28 ON ACTION previous
29 LET curr_cust = custquery.fetch_rel_cust(-1)
30 ON ACTION last
31 LET curr_cust = custquery.fetch_rel_cust(2)
32 ON ACTION append
33 LET curr_cust = custdata.append_cust(curr_cust)
34 IF curr_cust > 0 THEN
35 LET curr_cust = custquery.fetch_rel_cust(3)
36 END IF
37 CALL setup_dialog(DIALOG,(curr_cust>0))
38 ON ACTION update
39 LET curr_cust = custdata.update_cust(curr_cust)
40 IF curr_cust > 0 THEN
41 LET curr_cust = custquery.fetch_rel_cust(3)
42 END IF
43 CALL setup_dialog(DIALOG,(curr_cust>0))
44 ON ACTION delete
45 LET curr_cust = custdata.delete_cust(curr_cust)
46 CALL setup_dialog(DIALOG,(curr_cust>0))
47 ON ACTION quit
48 EXIT MENU
49 ON ACTION close
50 EXIT MENU
51 END MENU
52
53 CLOSE WINDOW w1
54
55 DISCONNECT CURRENT
56
57 END MAIN
58
59 PRIVATE FUNCTION setup_dialog(dlg ui.Dialog, can_nav BOOLEAN) RETURNS ()
60 CALL dlg.setActionActive("first",can_nav)
61 CALL dlg.setActionActive("next",can_nav)
62 CALL dlg.setActionActive("previous",can_nav)
63 CALL dlg.setActionActive("last",can_nav)
64 CALL dlg.setActionActive("append",TRUE)
65 CALL dlg.setActionActive("update",can_nav)
66 CALL dlg.setActionActive("delete",can_nav)
67 END FUNCTIONNote:
- Line
1imports public symbols from thecustquerymodule, implementing the query functions. - Lines
2imports the public symbols of thecustdatamodule, implementing the table modification functions. - Line
5defines thecurr_custvariable with the public typet_cust_numdefined in thecustdatamodule. The variable holds the current customer number, which is assigned when browing in the result. This number is passed to data modification functions when triggered. - Lines
21thru23: After a QBE query, we fetch the first row of the result set with thecustquery.fetch_rel_cust(0)call, which returns the current customer number. - Lines
32thru36Theappendaction calls thecustdata.append_custfunction. If the function returns zero, it means that the new row was added into the database. A new query needs to be performed by the user to browse again the table rows. - Lines
38thru43Theupdateaction calls thecustdata.update_custfunction. If the function returns zero, it means that the row was updated in the database. A new query needs to be performed by the user to browse again the table rows. - Lines
44thru46Thedeleteaction calls thecustdata.delete_custfunction. If the function returns zero, it means that the row was deleted from the database. A new query needs to be performed by the user to browse again the table rows. - Lines
59thru67implement the dialog setup function that enables or disabled actions according to the context. After a query, all actions as available. After a data modification, most actions are disabled and need a new query to be again active.