Introduction
This tutorial is not intended to be a replacement for the Clarion
manuals, which contain excellent reference material and some good examples. But
learning a new subject is often made easier by being able to "read around" and
get different viewpoints to fill out your knowledge.
If you write any templates yourself please share them with other developers - send them to
me and I will make them available for download here.
Template Types
One of the hardest things to get a grip on when you start using the Clarion Template
Language is the difference between the various template types: #PROCEDURE, #EXTENSION,
#CODE and #CONTROL. These have the typical format of (Unique
Name,description),Attributes. As in:
#EXTENSION (ImpexGlobals, 'IMPEX Globals for ABC - Globals EXE\DLL'),
APPLICATION,hlp('~Contents')
Where ImpexGlobals is the unique identifier which appears in the list of templates in the
Template Registry.
#PROCEDURE Type
This is the largest type in terms of possible functionality and includes the common types
such as Browse, Form etc. When you press Insert in the AppGen its a list of #PROCEDURE
templates that appears for you to choose from. The other three types of templates all
"hang off" this type. For beginners I would recommend becoming familiar with
these other smaller template types first.
#EXTENSION Type
To me this is the most useful template because you can put it on any type of procedure and
add your own functionailty such as Procedure Routines very easily. Typically you use the
#AT() statement to put code directly into a procedure's #EMBED points.
An example would be a security template where you want to log all users coming into a
procedure and what action they are taking. One way would be at the exit point of the
procedure, before files are closed, where you can write out the details to a file:
#AT (%WindowManagerMethodCodeSection, 'Kill','(),BYTE'), PRIORITY(5010)
LOG:ProcedureName='%Procedure'
LOG:FileName='%Primary'
LOG:UserID=USR:UserID
LOG:Action=SELF.Request
LOG:Date=TODAY()
LOG:time=CLOCK()
ACCESS:LogFile.Insert()
#ENDAT
Template symbols begin with % and there is a full list in the Programmers Guide. %Procedure
is the name of the current procedure and %Primary is the name of the main file
selected in the File Schematic. Note they are put in inverted commas. This is so that they
will be treated like literal text by the compiler.
#CODE Type
This template only appears in one place - when you click on an embed point you will see a
list of the available code templates. Such as SetProperty and CloseCurrentWindow.
#CONTROL Type
Unlike the previous two types a CONTROL template is tied to a specific window control,
such as a file lookup button. It will usually both place the control on the window (in the
Window Formatter the menu option is Populate Control Template) and also generate the
source code into embed points.
In Summary
The templates are the "scripts" which "drive" the AppGen - they
control what source code is generated for the compiler to work on. So if you take the time
to learn the Template Language you will have outstanding control over your applications.
As the saying goes: "If you write it more than once you should put it in a
template"!
If you need help with your template writing or want some templates writing to order please
email me: Mike McLoughlin
|