15. Writing a Template Assistant : How You Can Ensure Compatibility Between the Assistant and ApplyTemplate : Example—ApplyTemplate Compatibility : How You Can Attach the Assistant to a Frame Template
 
Share this page                  
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 its editor, and specify Create_Dyn_Fld as the assistant procedure.
When a user frame created from the My_Frame_Template frame template is run through the ApplyTemplate utility, any modifications made to the frame outside of the composite field defined by the $_TopComposite macro variable is unaffected.
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;
topcomposite = CompositeField default null;
status = integer not null;
find_top_composite = procedure returning CompositeField;
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;
topcomposite = callproc
    find_top_composite(composite = fs.topform);
trim_field.ParentField = topcomposite;

return_code = ER_OK;
return;
end;
procedure find_top_composite
(
composite = compositefield;
)=

declare
child = compositefield default null;
i = integer not null;
enddeclare
begin
if composite.name = 'FreetrimComposite' then
return composite;
endif;
for i = 1 to composite.childfields.lastrow() do
if composite.childfields[i].isa(class =
    CompositeField) = TRUE then
        child = find_top_composite(composite =
            composite.childfields[i]);
        if child IS NOT NULL then
            return child;
        endif;
endif;
endfor;
return NULL;
end;