14. Creating a Frame at Runtime : How You Can Build a Frame Dynamically : How You Can Create the FrameSource Object : How You Can Add the Frame to the Application
 
Share this page                  
How You Can Add the Frame to the Application
After the frame has been fully defined, it must be attached to the application by setting the ParentApplication attribute of the new frame's FrameSource object to the same value that is in the ParentApplication attribute of the currently executing frame. (The currently executing frame is the starting frame of the dynamic application.)
The following code from the example application sets the ParentApplication attribute of the generated frame:
test_frame.ParentApplication =
    CurFrame.ObjectSource.ParentApplication;
This statement assigns the contents of the ParentApplication attribute of the current frame's FrameSource object to the corresponding attribute of the generated frame's FrameSource object. For a more detailed explanation of the preceding syntax, see How You Can Attach the Frame to the Application (see How You Can Attach the Frame to the Application).
The DynamicFrame frame performs the additional step of adding the frame to a list of already generated frames. Because the sample application lets a user return to the initial frame, select another table, and select the Go menu item again, a global array variable is used to keep track of which frames have already been generated.
Because the Generated_Frame_List global variable stores the names of generated frames, an existing frame can be executed without requiring regeneration if the user selects a table for which a frame already exists.
The following code from the example application adds the newly generated frame to the list in the global array variable:
i = Generated_Frame_List.LastRow + 1;
Generated_Frame_List[i].table_name = table_choices;
Generated_Frame_List[i].frame_name = table_choices +
    '_frame';
Generated_Frame_List[i].frame_source = test_frame;
The global array variable, Generated_Frame_List, has three attributes: table_name, frame_name, and frame_source. The previous code uses the LastRow attribute (defined for the ArrayObject class) to determine the row sequence number of the last row in the array. The current value of the LastRow attribute is incremented by one to create a new index into the array.
The reference to a previously non-existent row automatically appends a new, empty row to the end of the array. After the row has been added, each of its attributes is assigned the appropriate value for the newly generated frame. The process used to add a new row in the example code is called adding a row by first reference. For more information about adding rows to an array, see Working with Arrays, Table Fields, and Collections (see Working with Arrays, Table Fields, and Collections).