Simply Clarion - Converting Simple Templates to ABC: Part 1

by Don Reynolds

Published 1998-02-01    Printer-friendly version

Simple Templates

Over the past issues, several templates have been shared in the Simply Clarion column. These include:

  • A Simple File Error Template
  • A Simple Conversion Logging Template
  • A Simple Button Security Template
  • A Simple Yes/No Template
  • A Simple Deselect Control Template

Now that the new ABC templates are out you may want to know if these templates will work with the ABC templates. I know I wanted to know this. More important, you may want to develop a strategy for converting the wonderful templates you write to ABC. Let me share with you what I did.

Reengineering

As you know, templates are used to generate pieces of code consistently. Once the template is built, instead of many lines of code, you insert a template, possibly answer a few questions, and continue on your way without worrying about whether the syntax is correct. Prior to building the template, you may have had code you found yourself repeating and you said to yourself, this is a good candidate for a template.

To test the templates with the ABC, I’ve followed this procedure backwards.

Step 1: A test application

First I created a small test application where I could use each of the templates. Since the function of the application was to exercise the templates, I could call the file error template, with an appropriate message, even though there was no file error. Testing out this application took a few moments. After all, it was using previously tested embeds.

Step 2: Cloning the Source

For each of the procedures I used to test the templates, I created a Source procedure. I copied the appropriate source code created during compilation in Step 1 into these procedures. I reran a second set of tests using both template generated and non-template generated code. The tests were identical. I then removed the original, template-generated procedures. This gave me an application with no simple templates in it, but which had the identical functionality. Listings of each of the appropriate procedures were produced…these would be the ‘before’ code.

Step 3: Conversion to ABC

I then ran the application modified in Step 2 through the application converter. Tension was building to see what kind of magic this would perform. Of course, I recompiled and retested. Same results. So far, so good.

Step 4: Analyzing the converted code

The next step was to analyze the code created in step 3. Listings were produced of the appropriate procedures and compared with the listings produced in step 2. This produced some surprises. Good ones.

Surprise #1

In most of the cases, the code was exactly the same. Since the functions being performed were fairly simple, this made sense. For example, several of the templates use the MESSAGE function. Since this function transfers straight across, the created syntax should be the same. This led to

Surprise #2

Many of the templates could be ported over with little changing. One change, however, does need to be made. Since there are now ‘families’ of templates, the #TEMPLATE line needs to be changed as follows:

Before

#TEMPLATE(MYTEMPLATE,’My wonderful template’)

After

#TEMPLATE(MYTEMPLATE,’My wonderful template’),FAMILY(‘ABC’,’Clarion’)

This allows MYTEMPLATE to be used in both the ABC and the Clarion families of template. Of course MYTEMPLATE, and ‘My wonderful template’ would represent whatever names you have in your template.

Step 5: Porting the templates

Simple templates were copied over to a subdirectory under Clarion 4. The above changes were made and the templates registered.

Step 6 Back to Templates

I reopened the Clarion 4 application, removed the appropriate source procedures and embeds, and made new ones using the templates. After recompiling the application, I reran the tests. Still same results. Things were looking good.

Surprise #3

One of the templates, A Simple Conversion Logging Template, creates a log file and writes entries to it. When I ran this through the converter, the source did not change at all. I thought it would have changed based upon the ABC file syntax, but it did not. I was particularly interested to see if this template would work when compiled. It did.

A Quicker Way Next Time

Having done the above steps, in minute detail, I’ve resolved to test the next set of templates by adding the family, registering the set, and then testing them. When I find templates which do not convert, I’ll repeat the detail steps listed above.

Conclusion

Converting simple templates to be used in the ABC chain will frequently be a simple, relatively painless process. Care should be taken to test that each template works.

Printer-friendly version

 
 

Search

 

Advanced Search
Topical Index

Related Articles

Subscribe to
ClarionMag

One year: $184

(includes all back issues since '99)

Renewals from $134

Two years: $274

Renewals from $224

More Info

Subscribe Now!

ClarionMag Blog

RSS Feeds

Updates via Email

Enter your Email


Powered by FeedBlitz

Quick Links