|
|
Sage-ST
ä
Tutorial
|
1. Overview.
In this lesson you will implement a CheckLib procedure to ensure that the user cannot enter an invalid employee's organization number.
2. What You'll Use.
You will use the following new calls:
acquire command,
CheckLib.ADB,
Display.RefreshCheckScreen,
Display.ForceFieldCheck.
3. Assignment.
Currently, before adding or modifying an employee, you check the OrgNum to be sure it is valid. If not, no addition or modification is done. There are several problems with this. First, the user has entered a whole screen of data and now must re-enter all of it after he or she finds out the correct OrgNum. Second, the user doesn't find out he or she has made a mistake until it is too late. It would be much better to notify the user immediately after typing in the OrgNum that it was wrong.
Each time a user edits a field on a form and attempts to leave that field, Sage-ST calls a function called CheckLib.FieldCheck. If FieldCheck returns a true, execution continues; if FieldCheck returns a false, Sage-ST will not allow the cursor to move on to the next field on the form. A CheckLib.ADB currently exists in the Sage-ST library, but it consists only of a null statement and always returns true.
Create a new CheckLib.ADB that will check the Employee.OrgNum field to be sure the OrgNum is valid. The package must be called CheckLib, and it must contain the function FieldCheck with the parameters indicated in Volume 2,
Reference Manual
.
The relation and field name of the current cursor position will be passed in to FieldCheck. If the field is the one you wish to check, call a function that you write to do the actual check. If OrgNum is valid, simply allow the process to continue. If invalid, display a message to the user informing him or her of the error.
Experiment with RefreshCheckScreen and ForceFieldCheck set to both false and true.
Before compiling CheckLib.ADB it must be acquired into your library. The following command can be put into a batch file.
ada unit_manager(%1,update).acquire(checklib,c:\ada\sagelib,alternate,overwrite= yes)
where "%1" is the path and name of your library. At the DOS prompt, type in the batch file name and the path and name of your library.
NOTE:
Ada unit_manager is Alsys specific. If you use the Meridian compiler, you must compile the CheckLib.ADB into your local library
.
HELPFUL HINT: Do NOT create or compile a CheckLib.ADS. However, if you do, delete your working library (not the Sage-ST library), reacquire CheckLib.ADB, and recompile and rebind your system.
4. Our Solution.
with Display;
with ModSys ;
with Sage ;
with Strings; use Strings;
package body CheckLib is
--*
-- Prototype 24 - complex edits can be made during data entry using CheckLib.
-- Sage-ST is initially compiled with a no-action CheckLib.ADB. In order to
-- use CheckLib you must first execute the following ALSYS command after
-- Sage-ST has been successfully installed:
--
-- ada unit_manager(mylib,update).
-- acquire(checklib,c:\ada\sagelib,alternate,overwrite=yes)
--
-- Substitute your development library name for "mylib".
--
-- When you installed Sage-ST, several batch files were given to you. One of
-- those is GETCHECK.BAT, which contains the above command line. This command
-- only needs to be executed one time. DO NOT COMPILE A CHECKLIB.ADS - it has
-- already been compiled in Sage-ST.
--
function Check_Employee_OrgNum return boolean is
begin
Sage.ReadRecordR ("Org", "OrgNum", Sage.EQ, "Employee", "OrgNum");
if Sage.SageError = 0 then
return TRUE;
else
Display.DisplayMessage ("Department number not currently valid",
TRUE);
return FALSE;
end if;
end Check_Employee_OrgNum;
function FieldCheck (relation : in string;
field : in string) return boolean is
begin
if (Strings.Compare (field, "OrgNum[1]") = Strings.equal) and then
(Strings.Compare (relation, "Employee") = Strings.equal) then
return Check_Employee_OrgNum;
end if;
return true;
end FieldCheck;
end CheckLib;
Go Back To
Tutorial Table of Contents