Example: custlistmod.4gl (Function custarr_display)
The custlistmod.4gl module implements the DISPLAY
ARRAY dialog in the custarr_display function.
The
custarr_display function in
custlistmod.4gl: 1 PRIVATE FUNCTION custarr_display_modif() RETURNS ()
2 DEFINE x INTEGER
3 DEFINE rec t_custrec
4
5 LET int_flag = FALSE
6
7 DISPLAY ARRAY custarr TO sa_cust.*
8 ATTRIBUTES(UNBUFFERED,
9 CANCEL = FALSE,
10 DOUBLECLICK = update)
11
12 ON APPEND
13 LET x = DIALOG.getCurrentRow("sa_cust")
14 INITIALIZE rec.* TO NULL
15 LET rec.cust_num = 1000 + x
16 LET rec.cust_name = "<undefined>"
17 INPUT rec.* WITHOUT DEFAULTS FROM sa_cust[scr_line()].* ;
18 IF NOT int_flag THEN
19 TRY
20 INSERT INTO customer VALUES (rec.*)
21 LET custarr[x] = rec
22 CATCH
23 ERROR SQLERRMESSAGE
24 LET int_flag = TRUE
25 END TRY
26 END IF
27
28 ON UPDATE
29 LET x = DIALOG.getCurrentRow("sa_cust")
30 LET rec = custarr[x]
31 INPUT rec.* WITHOUT DEFAULTS FROM sa_cust[scr_line()].* ;
32 IF NOT int_flag THEN
33 TRY
34 UPDATE customer SET customer.* = rec.*
35 WHERE cust_num = rec.cust_num
36 IF sqlca.sqlerrd[3] == 0 THEN
37 ERROR "The row has been deleted by another user."
38 LET int_flag = TRUE
39 ELSE
40 LET custarr[x] = rec
41 END IF
42 CATCH
43 ERROR SQLERRMESSAGE
44 LET int_flag = TRUE
45 END TRY
46 END IF
47
48 ON DELETE
49 LET x = DIALOG.getCurrentRow("sa_cust")
50 LET int_flag = NOT comutils.mbox_yn("Customers",
51 "Do you want to delete the current row?")
52 IF NOT int_flag THEN
53 TRY
54 DELETE FROM customer WHERE cust_num = custarr[x].cust_num
55 CATCH
56 ERROR SQLERRMESSAGE
57 LET int_flag = TRUE
58 END TRY
59 END IF
60
61 END DISPLAY
62
63 END FUNCTIONNote:
- Line
1defines the function, taking no parameters and returning no values. - Line
3defines therecrecord witht thet_cusrectype defined in the top of the module. - Line
7declares theDISPLAY ARRAYdialog, by using the custarr dynamic array defined as module variable (available in this scope), and binding the structured array to the form fields grouped in thesa_custscreen array. - Line
8:UNBUFFEREDis best practice in this context. - Line
9: We do not need the"cancel"action created implictly forDISLPAY ARRAYdialogs. We only want to keep the"accept"(OK button) action. - Lines
12thru26define theON APPENDblock. Go to The ON APPEND trigger for more details. - Lines
28thru46define theON UPDATEblock. Go to The ON UPDATE trigger for more details. - Lines
48thry59define theON DELETEblock. Go to The ON DELETE trigger for more details.