Simply Clarion - A Simple Deselect Control Template

By Don Reynolds

Posted December 1 1997

Printer-friendly version

Download the code here

Use of Code Files

If you know all about using code files and how to use selection controls, you can skip the next several sections and proceed to Deselecting an Entry. Otherwise read on.

We use code files a lot for several reasons including:

  • They take less physical space
  • They provide consistency in selections
  • They provide a level of security if only certain people are allowed to change them.

In the dictionary above, the file Person uses the following codes:

  • PrimaryProfession
  • SecondaryProfession
  • Primary Avocation
  • SecondaryAvocation
  • HighestEducation

Reducing the number of Code files

An application may have dozens of code files. We reduce the number of these files by consolidating multiple code files with like definitions into one 'allcodes' file. Into this file we put a 'class' field which identifies what kind of code file each record is. Another file contains the definitions of classes.

Since one person's profession may be another's avocation we needed two classes for the above examples:

  • Profession or Avocation
  • Highest Education

Multiple relationships between files

Frequently we have a file which has several codes within it. This creates multiple relationships between the primary file and the code file. Most of the time we will create this system without creating aliases for all the codes. Instead we have created template sets which handle selecting an appropriate code. There is no relationship defined within the dictionary between the primary file and the code file.

In the dictionary above, there are five relationships between Person and AllCodes.

Selecting A Code

Selecting a code is initiated through a control put on a screen with a prompt '...' similar to other controls with like features. Our control initializes a global variable for class. A single selection routine is called regardless of the class being used. We display the class as part of the screen heading so it looks like there are really multiple screens.

The database used for this article

Person           FILE,DRIVER('TOPSPEED'),PRE(PER),BINDABLE
ByPERId            KEY(PER:PERId),NOCASE,OPT,PRIMARY
ByLastFirstName    KEY(PER:LastName,PER:FirstName),DUP,NOCASE,OPT
Record             RECORD
PERId                LONG
LastName             STRING(20)
FirstName            STRING(20)
PrimaryProfession    LONG
SecondaryProfession  LONG
PrimaryAvocation     LONG
SecondaryAvocation   LONG
HighestEducation     LONG
                   END
                 END

AllClasses       FILE,DRIVER('TOPSPEED'),PRE(CLS),BINDABLE
ByCLSId            KEY(CLS:CLSId),NOCASE,OPT,PRIMARY
ByClassCode        KEY(CLS:ClassCode),DUP,NOCASE,OPT
ByDescription      KEY(CLS:Description),DUP,NOCASE,OPT
Record             RECORD
CLSId                LONG
ClassCode            STRING(2)
Description          STRING(20)
                   END
                 END

AllCodes         FILE,DRIVER('TOPSPEED'),PRE(COD),BINDABLE
ByAnyId            KEY(COD:ANYId),NOCASE,OPT,PRIMARY
ByCode             KEY(COD:Class,COD:Code),DUP,NOCASE,OPT
ByName             KEY(COD:Name),DUP,NOCASE,OPT
Record             RECORD
ANYId                LONG
Class                STRING(2)
Code                 STRING(4)
Name                 STRING(30)
                   END
                 END

The above dictionary is not meant as a final product, but is useful in illustrating this article.

Walk us through an example

From the browse we select Insert to add a record. We enter the last name and first name and find ourselves with a screen like this:

This is a single record window
This is a single record window

We wish to add a primary profession and do so by clicking on the button '...'. This brings up a browse box where we can select the primary profession. We highlight Midwife and press Select.

Dwr202.gif

Midwife appears on our Form and the linking code is entered into our record.

Dwr203.gif

Now we want to enter the primary avocation. We press '...' to select an avocation. (Note: this is the same selection procedure we used for Profession). We highlight Gardening and press Select.

Dwr204.gif

Gardening appears correctly on our Form. Internal keys are set.

Dwr205.gif

We follow similar procedures to set up secondary professions and avocations.

Dwr206.gif

Now we want to select the highest education. This should be easy. (Still using the same selection procedure)

Dwr207.gif

We end up with the following record all nicely filled out:

Dwr208.gif

Up to this point the above functionality can be duplicated by any of several means in Clarion.

Deselecting an Entry

However, Betsy may decide having that second career as a Carpenter isn't worth the hassle. So we want to remove that selection. Using the templates as originally designed only lets us select another entry. What we need is a way to explicitly deselect an entry. For this we created a control template as follows:

The Template

#TEMPLATE(SMPL0005,'Simple Deselect Button')
#CONTROL(DeselectButton,'Deselect Button'),DESCRIPTION('Deselect Button'),WINDOW
  CONTROLS
    BUTTON(' Deselect '),AT(,,40,12),USE(?Deselect),MSG('Deselect any entry')
  END
#DISPLAY('')
#PROMPT('Select file to Deselect',FILE),%FiletoDeselect,REQ
#DISPLAY('')
#ATSTART
  #DECLARE(%DeselectButton)
  #FOR(%Control),WHERE(%ControlInstance=%ActiveTemplateInstance)
    #SET(%DeselectButton,%Control)
  #ENDFOR
#ENDAT
#AT(%ControlEventHandling,%DeselectButton,'Accepted')
  #FIX(%File,%FiletoDeselect)
OPEN(%File)
CLEAR(%FilePrefix:Record)
LocalResponse = RequestCompleted
DO ProcedureReturn
#END

Using the Template

First we register the template as we would any template.

Back in the app generator we select the procedure where we select a code. While editing the Window, we select Populate from the menu, Control Template, Deselect Button. This puts a button with the prompt 'Deselect' on the window.

Dwr209.gif

Then we right click on the Deselect button and select actions. A new window pops up.

Dwr210.gif

We press on the '...' control to select a file.

Dwr211.gif

We highlight AllCodes (The code file in this particular case) and press Select.

Dwr212.gif

We press OK. Our Deselect Template has been set up. We then compile the program and run it. For Betsy, we update her record, and press the '...' associated with Secondary Profession. The Select a code screen appears and we press 'Deselect'.

Dwr215.gif

The Secondary Profession no longer appears on our screen in One Person Record. The internal keys have

Been set to zero.

Dwr214.gif

Summary

This gives us a quick way to deploy a deselect button into our applications. It functions in a manner similar, yet opposite to, the select button.

Notes

Some fields in the dictionary are used for ease in programming and are not essential in the strictest sense. The String code fields are a case in point. Instead of priming global fields with numerics, we prefer to use string fields. Acronyms seem easier for us to use inside the program. These are not needed in the Deselect template, but used in some of the selection templates. The tradeoff between ease of understanding and storage space seemed to us to be well worth it.

Article comments

Post a comment

You must be logged on to post comments.

Clarion Roadmap

Try the roadmap (beta)

Search ClarionMag

 

Advanced search

From the archives

The New Clarion.NET Template Language - Is It Really Microsoft's T4?

10/22/2009 12:00:00 AM

At the Aussie DevCon, SoftVelocity president Bob Zaunere demonstrated a template written in the new .NET template language. But is it a new template language? Dave Harms argues it's really Microsoft's T4, and explains why that's a good thing.