Dynamic multiple dialog
Dynamic dialogs allows to create the equivalent of a DIALOG
procedural
dialog.
Steps to implement a dynamic multiple dialog
The order in which dialog methods are called defines the structure of the dynamic multiple dialog.
- Create the multiple dialog with
createMultipleDialog()
. - Add global dialog triggers with
addTrigger()
. - Define the fields for a sub-dialog with a
DYNAMIC ARRAY OF RECORD
withname
andtype
members. - Add the sub-dialog with on of the following methods:
- Add sub-dialog triggers with
addTrigger()
. When calling this method after a sub-dialog item is added, it will create the trigger in the sub-dialog context. - Implement the
WHILE
loop using thenextEvent()
method, as for a simple dynamic dialog. However, sub-dialog triggers must be identified with the sub-dialog name.
Identifying global and sub-dialog actions
Sub-dialog actions are added with addTrigger(
in the context of a sub-dialog definition, after
calling a method such as "ON ACTION
action-name"
)addDisplayArrayTo()
.
In the even loop, the nextEvent()
method returns sub-dialog actions events with
the sub-dialog name prefix, using the "ON ACTION
sub-dialog-name.action-name"
text form:
...
CALL d.addDisplayArrayTo(, "sr_cust")
CALL d.addTrigger("ON ACTION refresh")
...
WHILE (t := d.nextEvent()) IS NOT NULL
CASE t
...
WHEN "ON ACTION sr_cust.refresh"
...
Identifying sub-dialog triggers
Sub-dialog triggers such as BEFORE DISPLAY
, BEFORE INPUT
can be
identified in the event loop with the sub-dialog identifier: The nextEvent()
method
returns the event text in the form "trigger-name
sub-dialog-name"
.
DISPLAY ARRAY
-style sub-dialog with the screen
record name "sr_cust", the trigger "BEFORE DISPLAY sr_cust"
will be generated when
the sr_cust
list gets the focus (as in a static DIALOG / END DIALOG multiple dialog
block):
...
CALL d.addDisplayArrayTo(, "sc_cust")
...
CALL d.addDisplayArrayTo(, "sc_prod")
...
WHILE (t := d.nextEvent()) IS NOT NULL
CASE t
...
WHEN "BEFORE DISPLAY sc_cust"
...
WHEN "AFTER DISPLAY sc_cust"
...
WHEN "BEFORE DISPLAY sc_prod"
...
WHEN "AFTER DISPLAY sc_prod"
...
Example
The next example defines a dynamic multiple dialog with a DISPLAY ARRAY
and a
CONSTRUCT BY NAME
sub-dialogs, and adds ON ACTION
triggers at
global and sub-dialog levels:
TYPE t_fields DYNAMIC ARRAY OF RECORD
name STRING,
type STRING
END RECORD
DEFINE d ui.Dialog,
list_fields t_fields,
qbe_fields t_fields
...
OPEN WINDOW w1 WITH FORM "myform"
...
LET d = ui.Dialog.createMultipleDialog()
-- add global triggers
CALL d.addTrigger("ON ACTION accept")
CALL d.addTrigger("ON ACTION cancel")
...
-- Add a DISPLAY ARRAY sub-dialog with name "sr_cust" (screen array)
CALL d.addDisplayArrayTo(list_fields, "sr_cust")
CALL d.addTrigger("ON ACTION refresh")
...
-- Add CONSTRUCT BY NAME sub-dialog with name "qr_cust"
CALL d.addConstructByName(qbe_fields, "qr_cust")
CALL d.addTrigger("ON ACTION query")
...
WHILE (t := d.nextEvent()) IS NOT NULL
CASE t
...
WHEN "ON ACTION sr_cust.refresh"
CALL refresh_list(d)
...
WHEN "ON ACTION qr_cust.query"
CALL exec_query(d)
...
WHEN "ON ACTION accept"
CALL d.accept()
WHEN "ON ACTION close"
EXIT WHILE
WHEN "AFTER DIALOG" -- after d.accept()
EXIT WHILE
END CASE
END WHILE
CALL d.close()
LET d = NULL
CLOSE WINDOW w1