Programming Guide : Writing a Template Assistant : How You Can Write an Assistant : Example--Frame Template Assistant
 
Share this page          
Example--Frame Template Assistant
In this example, a frame template assistant procedure has been designed to customize a frame template. The frame template assistant procedure prompts the user for a text string, assigns that string to a dynamically created FreeTrim field, and then places the field on the form.
First, the parameters are defined:
Procedure Create_Dyn_Fld
(
fs = FrameSource not null,
return_code = integer not null,
batch_mode = integer not null
)=
Because the procedure must support batch mode, a default string is specified. Otherwise, the user is prompted for the string:
if batch_mode = TRUE then
    text_string.value = 'Hello, world!';
else
    status  = curprocedure.replypopup(messagetext =
    'Enter text string.',
        reply = text_string);
        if status != PU_OK then
            return_code = ER_FAIL;
            return;
    endif;
endif;
Next, a text trim field is loaded with the specified text string:
trim_field = freetrim.create();
trim_field.textvalue = text_string.value;
Finally, the procedure must assign a value to the return code parameter and attach the composite field to the form:
trim_field.ParentField = fs.topform;
return_code = ER_OK;
How You Can Attach the Assistant to a Frame Template
In the same application that contains the Create_Dyn_Fld frame assistant procedure, a frame template can be created (for example, My_Frame_Template). To associate the frame template My_Frame_Template with its assistant, open the Property Inspector for the frame template in the Frame Editor, and specify Create_Dyn_Fld as the assistant procedure.
When a user frame is subsequently created from the template My_Frame_Template, the procedure Create_Dyn_Fld is called, which populates the new frame's form with a trim field entered by the user.
The full text of the frame assistant procedure is as follows:
Procedure Create_Dyn_Fld
(
fs = FrameSource not null,
return_code = integer not null,
batch_mode = integer not null
)=
declare
trim_field = FreeTrim default null;
text_string = StringObject;
status = integer not null;
enddeclare
begin
    if batch_mode = TRUE then
        text_string.value = 'Hello, world!';
else
        status  = curprocedure.replypopup(messagetext
            = 'Enter text string.',
            reply = text_string);
        if status != PU_OK then
            return_code = ER_FAIL;
            return;
        endif;
    endif;
    trim_field = freetrim.create();
    trim_field.textvalue = text_string.value;
    trim_field.ParentField = fs.TopForm;

    return_code = ER_OK;
    return;
end;