Construct Question

Started by Gary C., May 01, 2017, 12:51:10 PM

Previous topic - Next topic

Gary C.

Hello

I have a need to initialise the form values when using a construct statement, in essence "remembering" the users previous search criteria when entering the dialog.

Is this possible? I know I can read the field values but I am struggling to see how to set them.

Thanks

Daniel N.

Hello

in our applications we automatically save the construct values in a table and offer the user a button to restore the last saved values.

In AFTER CONSTRUCT we use the AUI Tree to find all elements that were part of the CONSTRUCT with SelectByPath("//*[@dialogType=\"Construct\"]")
and search their Attributes "name" and "value" with getAttribute("name")  and getAttribute("value"). 

If the user press the Button for "RestoreValues" we also use the AUI-Tree with the same SelectByPath and set the Attribute "value" with
setAttribute("value") with the saved contents for all contruct fields.

Daniel N.

Hello again

I don't know if you are familiy with AUI Tree. Attached please find the modified demo program Field.4gl and Field1.per to show
how you can get and restore the construct values.
Hope it helps.

Reuben B.

I like Andreas generic code.

The methods ui.Dialog.setFieldValue http://4js.com/online_documentation/fjs-fgl-manual-html/#c_fgl_ClassDialog_setFieldValue.html and ui.Dialog.getFieldValue http://4js.com/online_documentation/fjs-fgl-manual-html/#c_fgl_ClassDialog_getFieldValue.html introduced in 3.00 could be used instead of the AUI tree reading and writing and would be safer in the long run.

If you don't want to go down the generic code path then DISPLAY will do what you were after ...

Code (genero) Select
        CONSTRUCT BY NAME where_clause ON field1, field2, field3
        BEFORE CONSTRUCT
            DISPLAY ">0" TO field1
            CALL DIALOG.setFieldValue("field2", "A*")

        AFTER CONSTRUCT
            IF int_flag THEN
                EXIT CONSTRUCT
            END IF
            DISPLAY "Field 1 = ", GET_FLDBUF(field1)
            DISPLAY "Field 2 = ", DIALOG.getFieldValue("field2")
    END CONSTRUCT
    DISPLAY where_clause

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero

Gary C.

Hi

Thanks for your help Andrea/Reuben - I've got that working now.