14. Creating a Frame at Runtime : How You Can Build a Frame Dynamically : How You Can Create the Script : The Go Menu Item (Constructing the Frame)
 
Share this page                  
The Go Menu Item (Constructing the Frame)
After selecting a table, the user selects the Go menu item. Because the example application lets the user return to the initial frame to select another table, the code for the Go operation checks whether a frame already exists for the chosen table before generating a frame for that table. If such a frame exists, it executes the frame.
The following code from the example starting frame first checks whether the required frame exists. Then it executes the frame, if it does exist, or generates the frame and then executes it if it does not exist:
if Generated_Frame_List.LastRow >0 then
/* There is at least one generated frame. */
    for i = 1 to Generated_Frame_List.LastRow do
    if Generated_Frame_List[i].table_name =
        table_choices then
        /* Frame already there. Execute it. */
        callframe
        :Generated_Frame_List[i].frame_name;
        resume;
        endif;
    i = i + 1;
    endfor;
endif;
Generated_Frame_List is a global array variable used by the example application to keep track of frames that have already been generated, avoiding the need to regenerate them. The LastRow attribute, defined for array objects, returns the sequence number of the last row in the array. If the LastRow attribute returns any positive number in the preceding code, the code checks the Generated_Frame_List array for a table name that matches the user's chosen table. If a match is found, that frame is executed.
If no rows exist in the Generated_Frame_List variable or if no match is found, the starting frame code constructs a frame. The construction proceeds in the following order:
1. Create the FrameSource object and define its attributes.
2. Create the FrameForm object.
3. Construct the fields on the form.
4. Set the height and width of the form.
5. Complete the statement strings.
6. Create the menu items.
7. Generate the frame script for the frame.
8. Add the frame to the application.
After the frame is generated, it can be executed.
The following subsections describe each of these steps in detail.