14. Creating a Frame at Runtime : How You Can Build a Frame Dynamically : How You Can Create the FrameSource Object : How Generating the Frame Source Code Works
 
Share this page                  
How Generating the Frame Source Code Works
Part of the source code for the generated frame was written in the select loop that constructed the fields. The next section of the DynamicFrame frame script creates the generated frame's source code from the strings constructed in the select loop.
The starting frame uses the following steps to create the generated frame's source code:
1. Creates the string object to hold the completed script and assigns it to the Script attribute of the FrameSource:
test_frame.Script = StringObject.Create();
2. Constructs the script, creating an initialize block and event code for five Click events that correspond to the five MenuButton objects constructed earlier in the program (Commit, Rollback, Delete, Update, and Next).
The example frame uses the ConcatVarchar method (defined for the StringObject class) to concatenate the various pieces of the initialize statement and each event block into one large string. The ConcatVarchar method appends the string specified by the text parameter to the StringObject and returns a reference to the original StringObject.
The following code constructs the script for the generated frame:
/* Set up the initialize block */
test_frame.Script.ConcatVarchar(text =
    'initialize (table_cursor = CursorObject)
    =' + HC_NEWLINE + HC_TAB + 'begin' +
    HC_NEWLINE + HC_TAB + HC_TAB + selectstring +
    HC_NEWLINE);
test_frame.Script.ConcatVarchar
    (text = HC_TAB + HC_TAB +
    selectupdatestring + HC_NEWLINE + HC_TAB +
    HC_TAB + 'CurFrame.SendUserEvent
    (eventname = ''Next'');' +
    HC_NEWLINE + HC_TAB + 'end;' +
    HC_NEWLINE + HC_NEWLINE);
/* Set up the file.commit script */
test_frame.Script.ConcatVarchar(text =
    'on click file_menu.commit_menu = ' +
    HC_NEWLINE + HC_TAB +'begin' + HC_NEWLINE +
    HC_TAB + HC_TAB + 'close table_cursor;' +
    HC_NEWLINE + HC_TAB + HC_TAB + 'commit work;'
    + HC_NEWLINE + HC_TAB + HC_TAB + 'return;' +
    HC_NEWLINE + HC_TAB + 'end;' +
    HC_NEWLINE + HC_NEWLINE);
/* Set up the file.rollback script */
test_frame.Script.ConcatVarchar(text =
    on click file_menu.rollback_menu =
    ' + HC_NEWLINE + HC_TAB + 'begin' +
    HC_NEWLINE + HC_TAB + HC_TAB + 'close
    table_cursor;' + HC_NEWLINE + HC_TAB + HC_TAB
    + 'rollback work;' + HC_NEWLINE + HC_TAB
    + HC_TAB + 'return;' + HC_NEWLINE + HC_TAB +
    'end;' + HC_NEWLINE + HC_NEWLINE);
/* Set up the edit.delete script */
test_frame.Script.ConcatVarchar(text =
    'on click edit_menu.delete_menu =
    ' + HC_NEWLINE + HC_TAB +'begin' + HC_NEWLINE
    + HC_TAB + HC_TAB + 'delete from ' +
    table_choices + ' where current of
    table_cursor;' + HC_NEWLINE
    + HC_TAB + HC_TAB +
    'CurFrame.SendUserEvent(eventname =
    ''Next'');' + HC_NEWLINE+ HC_TAB + 'end;' +
    HC_NEWLINE + HC_NEWLINE);
/* Set up the edit.update script */
test_frame.Script.ConcatVarchar(text =
    'on click edit_menu.update_menu = ' +
    HC_NEWLINE + HC_TAB + 'begin' + HC_NEWLINE +
    HC_TAB + HC_TAB + updatestring +
    HC_NEWLINE + HC_TAB + HC_TAB + ' where
    current of table_cursor;'
    + HC_NEWLINE + HC_TAB + HC_TAB +
    'CurFrame.SendUserEvent
    (eventname = ''Next'');' + HC_NEWLINE
    + HC_TAB + 'end;' + HC_NEWLINE + HC_NEWLINE);
/* Set up the edit.next script */
test_frame.Script.ConcatVarchar(text =
    'on click edit_menu.next_menu,' +
    HC_NEWLINE + 'on userevent ''Next'' =' +
    HC_NEWLINE + HC_TAB + 'begin' +
    HC_NEWLINE + HC_TAB + HC_TAB +
    fetchstring + HC_NEWLINE + HC_TAB + HC_TAB +
    'if table_cursor.State = CS_NO_MORE_ROWS
    then'+ HC_NEWLINE + HC_TAB + HC_TAB + HC_TAB
    + 'message ''No more rows.'';' + HC_NEWLINE
    + HC_TAB + HC_TAB + 'endif;' + HC_NEWLINE +
    HC_TAB + 'end;' + HC_NEWLINE + HC_NEWLINE);
3. To facilitate debugging, writes the completed script to a file using the WriteToFile method (defined for the StringObject class):
test_frame.Script.WriteToFile("test.script");
The WriteToFile method invoked in the preceding example creates a file named test.script.