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 FUNCTION
Note:
- Line
1
defines thecustarr_display
function taking an SQL condition as parameter, and returning the customer number of the selected row. - Lines
5
thru8
call the functioncustarr_fill
to fill thecustarr
dynamic array, which has a scope local to the module, so it does not need to be passed as parameter. - Lines
12
thru29
implement theDISPLAY ARRAY
block to control the customer list. - Line
12
binds thecustarr
dynamic array to the sa_cust screen array, and uses theUNBUFFERED
option for this dialog. - Lines
13
to16
contain theBEFORE DISPLAY
block, 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.setArrayAttributes
method, and enables multi-row selection with theDIALOG.setSelectionMode
method call. - Lines
17
thru24
define theBEFORE ROW
block, which is executed each time the user changes the current row. - Line
18
gets the current row index in the record list. - Lines
19
thru24
display the values of the address, contact and phone number of the current row, to the form fields of theGRID
container. - Lines
25
and26
define 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
31
thru35
check theint_flag
register, to determine if the user has validated or canceled the dialog, and returns the -1 or the customer number of the selected row.