Clarion has a Secret Weapon? Where?

by Mike Lawson

Published 1998-09-01    Printer-friendly version

Well, it's not really that much of a secret.

Clarion has a feature that I'm convinced a lot of programmers don't use to its fullest. This is the ability to thread files throughout an application. While we generally know this allows independent views of the data, it can be used in much more useful ways. This feature is a lot more powerful than described in the Clarion manuals. Not only can a single file be opened and browsed through multiple MDI child procedures, but also a completely different file can be opened as long as it has the same structure.

I'm sure lots of you have figured this one out and have been using it for quite some time. I've also seen some references to this on the forums, but only people who have been using Clarion for awhile seemed to have found this feature. I feel this one item can be overlooked when most of us learn the language for the first time since the IDE doesn't seem to support it very well. When I first discovered the feature in Version 1.5, I was amazed at how easily it could be added and used to enhance even a simple program. Actually, it was like "WOW, I DIDN"T KNOW YOU COULD DO THIS!" (Remember I'd been programming in CFD 2.1.)

Why Two Parts?

If you are an advanced user I'm probably not going to cover any new ground in this article, but Part II might be interesting because I'd like some feedback. This article was taken from a talk I gave at our Hartford Users Group meeting last year and some of my information may seem little dated. For one thing I haven't done anything to change the code I present into ABC. I also didn't have enough sample code to really present this topic in full detail. So I've divided the article into two pieces. In the first one, I'm just presenting the topic; next month I'd like to share some more recent code. Also I'd like some feedback from other users who have used this technique in their applications. You can contact me at MichaelLawson@home.com (my home email account).

That means I want to hear from the readers of Clarion Online about the concepts I've presented here. I'd like to know if you found this feature by accident (As I did), or was it shown to you by someone else? Do you have a product that uses this feature extensively? Was this a feature you just figured out by reading this article? Is this anywhere in the manual or those README.TXT files we never read? As I state below a lot of commercial products don't seem to support MDI in useful ways and Clarion makes it all too easy.

How this feature can improve your applications.

PIM or Personal Information Managers have been around for sometime now. While it's not likely you are going to create a Lotus Organizer or Microsoft Outlook using Clarion in the next couple of months, you might be able to do a better job if you use file threading within your application.

Programs like these generally allow multiple views of the same data or separate the data into folders. While this is an acceptable way of organizing data, I sometimes like to allow the user to look at a whole different set of data. Some programs will let you do this, but only with one set of data at once. Sometimes multiple instances of the program may be opened with different data sets but it can be a pain to make this fit, even on a large high-resolution monitor.

Lotus has it half right; at least you can pass around an Organizer file as one complete data set. As I mentioned previously, you are only allowed to fully open one Organizer file at once within a program. Although you can collaborate with others using e-mail or the other features built into this program, you can still only directly manipulate the data within one file. The idea here is to create an application that can open and directly access multiple data sets within one program while keeping multiple files within a single DOS file that can be passed around or shared on a network. I think most of you realize I'm talking about the Topspeed file format here.

How to set things up.

A TopSpeed Super File is basically a DOS file that contains multiple Topspeed files. This concept is known as encapsulation, where one format is packaged and hidden in another. If you use SQL, these files would be similar to tables; Microsoft Access stores both data files and code in this manner. Please refer to the Clarion manuals -- now that you know what to look for it is pretty clear what these files where meant to do.

This type of storage has both benefits and drawbacks. The biggest drawback is that it leaves the DOS container file more susceptible to corruption. The major benefit is that all the files contained in the Super File use the same file handle. Since Topspeed Super Files don't contain code data and the TPSFIX utility does a reasonable job of recovering data, I think the benefits outweigh the risks. Because potential file corruption is a possibility, however, I usually include a utility that backs up the data by exporting the individual files to a safe place on a regular basis.

Well, since SQL does a similar job and is a lot quicker why not just use that instead? SQL is great if you're somehow connected to an SQL server, or have a local copy of the data on your hard drive. Even with large hard disk storage it's still awfully hard to pass around an SQL database on a disk. Since most people aren't storing a lot of information locally anyway, a compact portable database that can be downloaded to a central office later makes a lot of sense. Clarion has all the tools built in it to do this very easily, but it's just not that apparent.

Clarion is generally used to write programs that manage some kind of information; threading file data can add many benefits to an application. Clarion uses threads and opens its files in a shared mode by default, but it is usually the same set of files. If the file name is a variable, as in the screen shot below, it may be changed at any time. Take this a level higher and use a Topspeed Super File to encapsulate the data set and you have a compact, portable file system.

Image01.gif

Now imagine multiple files all with a variable file name like the !OpenCandidates value contained in the Full Pathname entry above (These have to be in Topspeed File format in order to work). Join the files normally and use a variable for the Full Pathname in all the dictionary entries that you want to encapsulate into your Topspeed Super File.

Next, for all the files you just joined, create a Global Variable in the dictionary using the Full Pathname (minus the ! sign of course). You now have a variable to hold a file name for each of the entries in your dictionary. Normally the file names would be set from an INI file or under program control.

Now make sure none of the files you set up this way get opened when the application starts, unless you have set a default value for the Full Pathname variables (The ones you just created in the previous step). You must then embed some code in the procedures that will access these files and ask for a file name, if none is present or a new one is needed. See the Source Code below:

IF FILEDIALOG(Glo:FileDialogTitle,OpenPath,'¦SuperFiles¦°.tps')
  OpenCandidates=Clip(OpenPath)&'\!Candidates'
  Open2ndFile =Clip(OpenPath)&'\!Open2ndFile'
  Open3rdFile =Clip(OpenPath)&'\!Open3rdFile'
ELSE
  MESSAGE('Error Opening File')
  POST(Event:CloseWindow)
END

Please note that the return value in this case called OpenPath must be clipped; also the encapsulated file name must be preceded with '\!'. This code must be added in an embed point before the files are normally opened. Since this code works in both ABC and Clarion templates I'll leave that task up to the reader.

Summary

I told you it was easy! That's all you have to do to thread Topspeed data files. You should also have a way to create a different set of files, and figure out when you need to open them. If you haven't used this feature before, this introduction should be enough to get you started, and thinking of various uses. Next month I'll include some code and ways of manipulating the data between multiple data sets. Also, please remember to send any comments that might be useful or interesting.

Printer-friendly version

 
 

Search

 

Advanced Search
Topical Index

Related Articles

Subscribe to
ClarionMag

One year: $189

(includes all back issues since '99)

Renewals from $139

Two years: $289

Renewals from $239

More Info

Subscribe Now!

ClarionMag Blog

RSS Feeds

Updates via Email

Enter your Email


Powered by FeedBlitz

Quick Links