![]() |
|
Published 1997-12-01 Printer-friendly version
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:
In the dictionary above, the file Person uses the following codes:
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:
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 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.
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.
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 |
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.

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

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.

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

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

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

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

Up to this point the above functionality can be duplicated by any of several means in Clarion.
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:
#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
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.

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

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

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

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'.

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

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.
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.
Copyright © 1999-2008 by CoveComm Inc. All Rights Reserved. Reproduction in any form without the express written consent of CoveComm Inc., except as described in the subscription agreement, is prohibited.
Clarion Magazine ISSN 1718-9942
One year: $189
(includes all back issues since '99)
Renewals from $139
Two years: $289
Renewals from $239