15. Writing a Template Assistant : How You Can Write an Assistant : Example—Field Template Assistant : How You Can Attach the Assistant to a Field Template
 
Share this page                  
How You Can Attach the Assistant to a Field Template
In the same application that contains the frame assistant procedure Create_Label, a field template can be created (called, for example, My_Field_Template). This template should contain one composite field that consists of several entry fields, and one free trim field for the label with the variable name of “label.” To associate the field template My_Field_Template with its assistant, open the Property Inspector for the field template in its editor, and specify Create_Label as the assistant procedure.
When a form field is subsequently created from the template My_Field_Template, the procedure Create_Label is called, which populates the new label with the text string entered by the user.
The full text of the field assistant procedure is as follows:
Procedure Create_Label
(
ff = FormField not null,
return_code = integer not null,
batch_mode = integer not null
) =
declare
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;
field_obj = CompositeField(ff).FieldByName(name
    =  'label');
EntryField(field_obj).textvalue =
    text_string.value;
return_code = ER_OK;
return;
}
end;