It looks like the embed %AfterGeneratedApplication is a very popular embed these days.
We already talked about it in the Template Tips #2 post where we compare it with the #AT(%ProgramEnd). Now we’ll compare #AT(%AfterGeneratedApplication) with #ATEND, and we’ll explain which of these is appropriate for a given task.
Why do we compare #ATEND with #AT(%AfterGeneratedApplication) ?
Because both of these are executed at the end of the code generation process (when we click on the Generate button).
Some 3rd Party Templates have the need to execute code that requires the App to be have been generated, and you’ll find they make use of #ATEND or #AT(%AfterGeneratedApplication).
All of the templates support #ATEND, but we’ll focus on the #APPLICATION #ATEND embed.
The #ATEND is comparable to a Destructor of a class, it is executed at the end of a templates code generation cycle, and the purpose is typically to execute some clean up code. When I mention clean up code I’m not talking about generating backups, creating extra files, or doing some extra processing, etc. I’m talking about cleaning up template symbol values. Any other processing should not be executed in the #ATEND.
One of the reasons additional processing should not be executed in the #ATEND is that the #ATEND is similar to a Class Destructor, and that means the scope of the template is already ending, so just like in any other Class Destructor. you should not be creating new instances of anything at that point.
Another reason, that is more related to the templates is the Embeditor. What does the Embeditor have to do with the #APPLICATION #ATEND?
Well if you inspect the #APPLICATION code closely you will see that there is one magic part that make the Embeditor work.
I’m talking about this code:
#IF (%EditProcedure) #! Special for editing embedded source in context #CREATE(%EditFilename) #FIND(%ModuleProcedure,%EditProcedure) #FIX(%Procedure,%ModuleProcedure) #! Fix current procedure #MESSAGE('Generating Module: ' & %Module,1) #! Post generation message #MESSAGE('Generating Procedure: ' & %Procedure,2) #! Post generation message #GENERATE(%Procedure) #! Generate procedure code #COMMENT(60) #!Set comment alignment to column 60 #CLOSE #ABORT #!Stop execution of any other code #ENDIF
Yes, the Embeditor code is just the #GENERATION of the procedure with a little bit of magic.
Because this code is executed in the #APPLICATION section of the template we are expecting the #APPLICATION #ATEND to be executed.
Actually everything would be executed if it was not for the #ABORT at the end of the above code.
So if you are using the #ATEND, you are not only adding code to the equivalence of a Class Destructor, but you are also adding code that will always be executed unless you check for the value of the %EditFilename symbol. If the value of %EditFilename is null then you can be sure that you are in regular code generation, and not in the Embeditor generation. This is a very important point.
Where does the #AT(%AfterGeneratedApplication) fit into all this code generation?
Well the #EMBED(%AfterGeneratedApplication) is located at the end of the #APPLICATION template, it’s the last code to be generated before the #ATEND, but the big difference is that it only executes when we are generating the #APPLICATION during regular code generation. The execution of that embed will not happen on the Embeditor generation because of the #ABORT that we already mentioned.
The conclusion, if you need to execute code at the end of the Application generation process, I always recommend the use of the #AT(%AfterGeneratedApplication) instead of the #ATEND. And always try to use a PRIORITY, that will make other templates play nice with yours.
Hi,
Basically the person that write templates need to know what he/she is writing the template for and how that template behaves.
The %AfterGeneratedApplication is not a template symbol but an embed and the only way to get to know the embeds is to check the templates, that is something that a template writer should do anyways. The #ATEND is documented because it is part of the template language but maybe some documentation can be added about the embeds symbols.
One thing that struck me reading the blog was that there is no documentation
of the shipping templates symbols.
What I mean is you can search the Clarion Help and the Docs folder and find
information on the built in template symbols, but you won’t find
%AfterGeneratedApplication
because that’s a symbol in one of the shipping template set and none of them (unless I’m missing something) are documented.
It would surely help users creating their own templates if these shipping
template symbols and embed points were documented together with how to
‘properly’ use them.
Their mis-use seems to have been the cause of some of the C6 to C7
conversion issues.
Graham