Progress
Programming
Handbook


Forcing Frame-wide Validation

To make sure that your application does not have any validation holes, you have three options:

Using the USE–DICT–EXPS Frame Phrase Option

The USE–DICT–EXPS option of the frame phrase forces all Data Dictionary validation and help strings to be compiled into the frame on the first reference of a field in the frame. Note that this is different from the normal behavior. Data dictionary validation is compiled in on the first reference of the field in an input statement. For this reason, programmatic VALIDATE or HELP options must be added to the DEFINE FRAME, FORM, or DEFINE BROWSE statements to override existing Data Dictionary expressions. (The first reference of a field in the frame is normally the reference in one of these statements, unless the field is added later.)

This option may add a lot of non-essential code to a frame, so its use should be restricted to where necessary. The option is intended to be used with frames that might have fields enabled with the widget:SENSITIVE = YES syntax. It is not necessary in any other case.

Using the Dictionary Expressions (–dictexps) Startup Parameter

The Dictionary Expressions (–dictexps) startup parameter is intended to be used as a temporary step to close possible validation holes in existing applications. It has the effect of adding a USE–DICT–EXPS option to every frame in the application, including those that are not used for input. While this parameter quickly closes all possible validation holes, it is a highly inefficient way of doing it.

For best long-term results, search for and replace widget:SENSITIVE = YES constructs, or use the USE–DICT–EXPS option on effected frames.

For more information on the –dictexps parameter, see the Progress Startup Command and Parameter Reference.

Using the Frame VALIDATE( ) Method

However, you can force Progress to perform all established variable and field validations at any time by executing the VALIDATE( ) method for the frame. The method returns TRUE if all validate checks in the frame succeed. It returns FALSE for the first validate check that fails in the order that data representation widgets are specified in the frame definition. A typical application of this method is in a trigger for an event that accepts the current updates in the frame. If the method fails, Progress gives input focus to the widget that failed the test after the trigger returns to the blocking WAIT–FOR statement.

NOTE: You can also apply the VALIDATE( ) method to a single data representation widget to perform any validate check for the underlying field or variable of that widget. If the test fails, focus returns to the specified widget.

The following procedure shows the VALIDATE( ) method applied to a frame that is used to update existing item records in the sports database. Enter an item number and press RETURN. The procedure displays and enables fields from the selected record, if it is available. To update the record in the database and enter a new item number, choose the bContinue button.

Note that once an item record is enabled for update, the procedure does not allow the record to be written back to the database unless all the relevant fields pass the specified validate checks. This is true even if no input fields have been entered and no data has changed from the original record.

p-frmval.p
DEFINE BUTTON bContinue LABEL "Continue".
DEFINE BUTTON bQuit LABEL "Quit".
DEFINE FRAME ItemFrame
    item.item-num
    item.item-name
        VALIDATE(item-name BEGINS "B", 
                 "Must enter item-name starting with B")
    item.on-hand
        VALIDATE(on-hand > 0, "Must enter items on-hand > 0.")
    item.allocated
        VALIDATE(allocated <= on-hand, 
                 "Allocated cannot be greater than on-hand items.")
    bContinue
    bQuit
WITH SIDE-LABELS.

ON RETURN OF item.item-num IN FRAME ItemFrame DO:
    FIND FIRST item 
        WHERE item-num = INTEGER(item-num:SCREEN-VALUE) NO-ERROR.
    IF AVAILABLE(item) THEN DO:
        DISABLE item-num WITH FRAME ItemFrame.
        DISPLAY item-name on-hand allocated WITH FRAME ItemFrame.
        ENABLE ALL EXCEPT item-num WITH FRAME ItemFrame.
    END.
    ELSE DO:
        MESSAGE "Item not on file.  Enter another.".
        RETURN NO-APPLY.
    END.
END.
ON CHOOSE OF bContinue IN FRAME ItemFrame DO:
    IF NOT FRAME ItemFrame:VALIDATE() THEN
        RETURN NO-APPLY.
    ASSIGN item.item-name item.on-hand item.allocated.
    DISABLE ALL EXCEPT bQuit WITH FRAME ItemFrame.
    ENABLE item.item-num WITH FRAME ItemFrame.
END.

FIND FIRST item NO-ERROR.
DISPLAY 
    item.item-num item.item-name item.on-hand item.allocated 
    bContinue bQuit
WITH FRAME ItemFrame.
ENABLE item.item-num bQuit WITH FRAME ItemFrame.
WAIT-FOR CHOOSE OF bQuit IN FRAME ItemFrame.     


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095