Programming Guide : Creating Dynamic Frames : Conceptual Background
 
Share this page          
Conceptual Background
By changing a field or menu option's bias, you can change its appearance and behavior. Even objects created in OpenROAD Workbench can be changed at runtime. These changes include:
Appearance of menu options and buttons, which includes the following available states:
Enabled
Disabled
Invisible
Behavior of fields and frames, which includes the following available states:
Visible
Changeable
Resizable
Moveable
Landable
You can also create frames whose fields are added or deleted either at frame start-up or while the frame is running. Adding fields to a frame by creating them at runtime is a straightforward process. However, fields created dynamically do not have the data variables of most fields created in OpenROAD Workbench. Therefore, accessing the data values of these fields involves using methods and objects.
When you create a field in Workbench, the Variable Declared toggle field on the Property Inspector for that field defaults to on. The variable declared by default lets you access the field's data value directly. This data variable cannot be used to refer to the attributes of the object.
When you create a field in Workbench, you generally change the data variable name provided by default on its Property Inspector. You reference your data variable name in your 4GL code whenever you need to access the data in the field.
For example, assume that you create an entry field and overwrite the default variable name (Field0) as title. You can set the value in that field with the following statement:
title = 'Destry Rides Again';
It is not necessary to declare field and menu item variables in your scripts; OpenROAD declares them automatically when the Variable Declared toggle field is set to on. If you do declare title or another field name as a variable in your 4GL script, you get a compile error.
To reference the field object represented by a field or menu item instead of its value, use the field function with the data variable. For example, the following statement changes the background color of the entry field described in the previous code example:
field(title).bgcolor = CC_ORANGE;
When you create a field dynamically, you do so by declaring and instantiating a reference variable that points to the field object. You use that variable to set the field's attributes and attach it to the form. Because the field function operates on the data variable to return its reference variable, it is irrelevant to dynamically created fields. Fields created dynamically do not have a data variable.
Moreover, the field function is unnecessary with fields created dynamically because the variable used in creating the dynamic field references its field object. However, because the data value is not an attribute of an object, accessing the data value of such an object requires the GetFieldValue and SetFieldValue methods or the use of dynamic expressions (DynExpr).