The buffered and unbuffered modes

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.

With the UNBUFFERED attribute, program variables and form fields are automatically synchronized, and the instruction is sensitive to program variable changes: You don't need to display values explicitly with DISPLAY TO or DISPLAY BY NAME. When an action is triggered, the value of the current field is validated and is copied into the corresponding program variable. If you need to display new data during the DIALOG execution, just assign the values to the program variables; the runtime system will automatically display the values to the screen:
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.

To illustrate this case, imagine that you want to implement an undo action to allow the modifications done by the user to be reverted (before these have been saved to the database of course). You typically copy the current record into a clone variable when the dialog starts, and copy these old values back to the input record when the undo action is invoked. An undo action is a good candidate to avoid field validation, since you want to ignore current values. If you don't re-display the values, the input buffer of the current field will remain when returning from the ON ACTION block:
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