KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to populate and self-document an Array with a Form Object's Default Values
PRODUCT: 4D | VERSION: 15.1 | PLATFORM: Mac & Win
Published On: May 26, 2016

SITUATION: A form was constructed with a popup/dropdown menu object with its values stored in the objects "Defaut values" property.

TASK: Populate a Process variable array with the same name as the Variable name of the form object with the values stored in the form objects "Defaut values" property.

QUESTION: When is the first opertunity to capture the vaiues and how?

WHAT TO KNOW: The order in which the "On load" event fires between object methods and and form methods and why not to define the array in the Form method. Consider the image below...


When 4D opens a form and before it triggers any form events it scans all the form objects, defines and populates them with default values. Once the form objects have been scanned and defined, 4D triggers the On load form event. It send the trigger to the form and form objects in a very specific order. In the image above, the break point is set at the earlist possible point to intercept form events.

Notice that the form object Alignment_aT has already been, defined as an array, populated with the Default values and given the value of one. This is before any compiler directive is encountered. The order in which objects receive form events is explained below.

  • First to receive the On load event are the form objects on any Subforms, in their "Entry order," see image below...




  •     On this form, the form object "tblList_at" is the first object to receive form events and the "jsonList_at" is the second object to receive form events, etc.

  • Next to receive form events are Form methods for any Subforms.

  • Next to receive form events are the objects method of the form objects.

  • When it comes to subforms it can get confusing because the subform's form method has been sent form events and then the base form's Subform form object's object method gets sent form events. So be mindful what what and where code is to be executed.

  • Finally, the Form method of the base form recieves form events.

  • WHY: So, if 4D is typing, populating, and setting the value to the array, why would a developer want to declare the array as well? Self-documentation for future follow-on developers and any contextual element additions to the array.

    HOWTO: Consider the image below...



    The standard way of declaring this array would be...

    ARRAY TEXT(Alignment_aT;0)

    But doing this in any object or form method is going to wipe out the work 4D has already done to populate the array.

    So to preserve the work 4D has done and provide self-documentation and the opportunity to add contextual element to the array, this technique accomplishes both.