Example custlist.4gl (Function custarr_display)
The custlist.4gl module implements the DISPLAY
ARRAY dialog in the custlist_display function.
Function
custlist_display in custlist.4gl
module: 1 PRIVATE FUNCTION custarr_display(sql_cond STRING) RETURNS (LIKE customer.cust_num)
2 DEFINE cnt INTEGER,
3 x INTEGER
4
5 LET cnt = custarr_fill(sql_cond)
6 IF cnt == 0 THEN
7 RETURN 0
8 END IF
9
10 LET int_flag = FALSE
11
12 DISPLAY ARRAY custarr TO sa_cust.* ATTRIBUTES(UNBUFFERED)
13 BEFORE DISPLAY
14 MESSAGE ""
15 CALL DIALOG.setArrayAttributes("sa_cust",custatt)
16 CALL DIALOG.setSelectionMode("sa_cust",1)
17 BEFORE ROW
18 LET x = DIALOG.getCurrentRow("sa_cust")
19 DISPLAY custarr[x].addr,
20 custarr[x].contact_name,
21 custarr[x].phone
22 TO FORMONLY.cr_addr,
23 FORMONLY.cr_contact_name,
24 FORMONLY.cr_phone
25 AFTER DISPLAY
26 LET x = DIALOG.getCurrentRow("sa_cust")
27 ON ACTION refresh ATTRIBUTES(TEXT="Refresh",ACCELERATOR="F5")
28 LET cnt = custarr_fill(sql_cond)
29 END DISPLAY
30
31 IF int_flag THEN
32 RETURN -1
33 ELSE
34 RETURN custarr[x].cust_num
35 END IF
36
37 END FUNCTIONNote:
- Line
1defines thecustarr_displayfunction taking an SQL condition as parameter, and returning the customer number of the selected row. - Lines
5thru8call the functioncustarr_fillto fill thecustarrdynamic array, which has a scope local to the module, so it does not need to be passed as parameter. - Lines
12thru29implement theDISPLAY ARRAYblock to control the customer list. - Line
12binds thecustarrdynamic array to the sa_cust screen array, and uses theUNBUFFEREDoption for this dialog. - Lines
13to16contain theBEFORE DISPLAYblock, which is executed before giving the control to the dialog. The block clears the message and defines the dynamic array to be used to decorate cells with theDIALOG.setArrayAttributesmethod, and enables multi-row selection with theDIALOG.setSelectionModemethod call. - Lines
17thru24define theBEFORE ROWblock, which is executed each time the user changes the current row. - Line
18gets the current row index in the record list. - Lines
19thru24display the values of the address, contact and phone number of the current row, to the form fields of theGRIDcontainer. - Lines
25and26define the AFTER DISPLAY block, which is executed when the DISPLAY ARRAY dialog terminates, after the user has selected the OK or the Cancel button, or has issued a double-click on a row. - Lines
31thru35check theint_flagregister, to determine if the user has validated or canceled the dialog, and returns the -1 or the customer number of the selected row.