How You Can Create Dynamic Composite Fields
Composite fields are created dynamically using the same steps used to create a simple field. For a discussion of these steps, see
How You Can Create Dynamic Simple Fields.
However, creating a MatrixField object dynamically requires an additional step. When first instantiated, matrix fields contain no columns and no rows. Because you cannot insert a field into a matrix field cell that does not exist, you must specify the number of rows and columns before you insert any child fields.
Begin dynamic matrix field creation by specifying a number of rows and columns large enough to contain all the fields to be inserted. After all child fields have been added, remove the empty cells by setting the CollapsePolicy attribute.
The following code creates a matrix field, sets the number of rows and columns, populates the matrix field, and removes empty cells:
mfield = MatrixField.Create();
mfield.Rows = 25;
mfield.Columns = 4;
Loop through some array to get information about
each field to be added. Create fields and set their
attributes.
...
mfield.InsertChild(fieldtoinsert = trim,
row = i, column = 1);
mfield.InsertChild(fieldtoinsert = efields[j],
row = i, column = 2);
endfor;
/* get rid of extraneous rows */
mfield.CollapsePolicy = CP_ROWS;
For more information about the CollapsePolicy attribute of the MatrixField system class, see the Language Reference Guide.
How You Can Create Dynamic Table Fields and Table Field Columns
You can create table fields dynamically in the same way as other composite fields, or you can add new columns to an existing table field (so long as its underlying array has not been declared in OpenROAD Workbench).
To add or remove columns dynamically from a table field created in Workbench, the variable for the table field must not be declared until runtime. When you create the table field, set the Variable Declared property to off. At runtime, add or remove the requisite columns. After the table field contains only the desired columns, declare an array variable for the table field with the DeclareData method of the ActiveField system class.
The following section describes the process of dynamically adding columns to a table field. For a discussion of dynamically removing table field columns, see
How You Can Remove Columns from a Table Field. 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.
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;
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.