13. Creating Dynamic Frames : How You Can Create and Modify Fields Dynamically : How You Can Create Dynamic Composite Fields : How You Can Add a Column to a Table Field
 
Share this page                  
How You Can Add a Column to a Table Field
You can add a column to an existing table field using the following steps.
1. Create a form field to serve as the prototype field for the column.
Table fields are typically composed of entry fields, but the prototype can be any form field.
The following code instantiates an entry field object as a member of an array named efields:
efields[j] = EntryField.Create();
2. Assign appropriate attributes to the field.
You must give the field a name. If you do not supply a data type for an entry field, OpenROAD provides a default of varchar(100).
The following example sets attributes for an entry field to contain dates:
efields = EntryField.Create();
colname = 'some_string';
efields.Name = colname;
efields.DataType = 'date';
efields.FormatString = 'd"2/3/01"';
3. Insert the field into the table field, for example:
field(tfield).InsertColumn(fieldtoinsert = efields[j], position = j, title = colname);
If position is not specified, the column is inserted as the first column of the table field. The mandatory title parameter specifies the text for that column's title.
Inserting a field into a table field creates a ColumnField. The reference variable pointing to the column field is stored in the tblfld.TableBody.ChildFields array.
4. To change other attributes of the column's title, such as type size, reference the TitleTrim attribute of the ColumnField.
The following code changes the column's font style and size:
ColumnField(tfield.TableBody.ChildFields[j]).
    TitleTrim.IsBold = TRUE;
ColumnField(tfield.TableBody.ChildFields[j]).
    TitleTrim.TypeSize = 10;
You must cast a TableBody's child field to a ColumnField. For more information about casting, see How You Can Work with Attributes (see How You Can Work with Attributes).
After all columns have been added to the table field, create an array variable for the table field using the DeclareData method.
For a discussion of dynamically declaring the array variable for the table field, see How You Can Declare a Composite Field's Array Variable Dynamically (see How You Can Declare a Composite Field's Array Variable Dynamically).