Usage / Programming with DIALOG |
The variables act as a data model to display data or to get user input through theDIALOG instruction. Always use the variables if you want to change field values by program.
Synchronization of program variables with the form fields depends on the buffer mode used by the dialog. This applies also to secondary data models such as multi-row selection flags and cell display attributes. As a general programming pattern, use the UNBUFFERED mode to get automatic data/form synchronization.
When you use the default "buffered" mode, program variable changes are not automatically displayed to form fields; you need to execute DISPLAY TO or DISPLAY BY NAME. Additionally, if an action is triggered, the value of the current field is not validated and is not copied into the corresponding program variable. The only way to get the text of a field is to use GET_FLDBUF() or DIALOG.getFieldBuffer(). These functions return the current text, which might not be a valid representation of a value of the field data type.
DIALOG ATTRIBUTES(UNBUFFERED) INPUT BY NAME p_items.* ON CHANGE code IF p_items.code = "A34" THEN LET p_items.desc = "Item A34" END IF ... END INPUT END DIALOG
During data input, values entered by the user in form fields are automatically validated and copied into the program variables. Actually the value entered in form fields is first available in the form field buffer. This buffer can be queried with built-in functions or dialog class methods. When you use the UNBUFFERED mode, the field buffer is used to synchronize program variables each time control returns to the runtime system - for example, when the user clicks on a button to execute an action.
When you use the UNBUFFERED mode, data validation must be prevented for actions such as cancel or close . To avoid field validation for a given action, set the validate action default attribute to "no", in the .4ad file or in the ACTION DEFAULTS section of the form file:
ACTION DEFAULTS ACTION undo (TEXT = "Undo", VALIDATE = NO) ... END
Some predefined actions are already configured with validate=no in the default.4ad file.
If field validation is disabled for an action, the code executed in the ON ACTION block acts as if the dialog was in BUFFERED mode: The program variable is not set; however, the input buffer of the current field is updated. When returning from the user code, the dialog will not synchronize the form fields with program variables, and the current field will display the input buffer content. Therefore, if you change the value of the program variable during an ON ACTION block where validation is disabled, you must explicitly DISPLAY TO / BY NAME the values to the fields.
DIALOG ATTRIBUTES(UNBUFFERED) INPUT BY NAME p_cust.* BEFORE INPUT LET p_cust_copy.* = p_cust.* ON ACTION undo -- Defined with VALIDATE=NO LET p_cust.* = p_cust_copy.* DISPLAY BY NAME p_cust.* END INPUT END DIALOG