Programming Guide : Creating Dynamic Frames : How You Can Declare a Composite Field's Array Variable Dynamically : How You Can Declare and Undeclare Data
 
Share this page          
How You Can Declare and Undeclare Data
Before you can load data into a dynamically created or modified table field, perform the following operations:
1. Attach the table field to the form by parenting it (if it is not already parented).
2. Specify the table field's underlying array with the DeclareData method.
The following code declares an array variable (tarray), attaches the tfield table field to the current form, and declares tarray as the array associated with the tfield table field:
Declare
    tarray = ArrayObject default null;
enddeclare
...
tfield.ParentField = CurFrame.Topform;
tfield.DeclareData(result = byref(tarray));
In the process of declaring the table field's array variable, the DeclareData method creates a user class whose attributes match the columns in the associated table field. Unless you explicitly set the data type of the table field, after invoking the DeclareData method, the named array points to an initially empty array whose rows are objects of the user class created by the method.
In addition to creating a user class for the table field and creating a new array whose rows' class is the new user class, the DeclareData method adds the name of the table field to the scope of the frame to which it belongs. In this example, the scope is the current frame.
Because the table field's name has been added to the current frame's scope, that name can be used subsequently in dynamic expressions to refer to the array associated with the table field. Moreover, dynamic expressions can also refer to columns of the rows in the table field's array.
Note:  Because the user class is constructed to match the table field's columns, invoke the DeclareData method only after you have added or removed all the desired columns and given the table field a parent.