14. Creating a Frame at Runtime : How You Can Build a Frame Dynamically : How You Can Create the Script : How You Can Load Values into a ChoiceField Object
 
Share this page                  
How You Can Load Values into a ChoiceField Object
Because the statement that loads values into the table_choices option field uses the reference variable associated with the option field, the field function is required. For more information about the field function and its use, see Working with Classes (see Working with Classes) and Creating Dynamic Frames (see Creating Dynamic Frames).
As a ChoiceField object, one of the attributes of the table_choices option field is ValueList. ValueList contains the values in an enumerated list. The data type of ValueList is ChoiceList, which means that ValueList contains an object of the class ChoiceList.
A ChoiceList object has an attribute called ChoiceItems. The ChoiceItems attribute contains an array of class ChoiceItem with two attributes, EnumText and EnumValue. The EnumText attribute contains the text associated with the list; in the example frame, the value of EnumText is the table name. The EnumValue attribute contains an enumerated value associated with the text; the example frame uses the row number of the ChoiceItems array.
To access the EnumText and EnumValue attributes, you can move through the ChoiceItems array by incrementing the array index counter.
The following statement assigns the contents of the variable tmp_table_name to the EnumText attribute in the ith row of the array of ChoiceItem objects contained in the ChoiceItems attribute:
field(table_choices).ValueList.ChoiceItems[i].
    EnumText = tmp_table_name;
The ChoiceItems attribute is an attribute of the ChoiceList object that is contained in the ValueList attribute of the OptionField object represented by field(table_choices).
An alternative method for loading the ValueList attribute of a ChoiceField object is using the ChoiceList's AddTextItem or the AddBitmapItem methods. For an example of how to use the AddBitmapItem method, see Working with Images and Text Strings (see Working with Images and Text Strings).