Copyright 2007 by gINT Software. All rights reserved worldwide.
GR010.TXT
gINT Rules Code Samples - 010
Requires gINT version 6.1.016 or later.
NOTE: Code samples are provided free of charge and as-is. gINT Software makes no claim or warranty as to the accuracy of the samples. It is the responsibility of the user to ensure that the code performs as it should. Comments, suggestions, and error reports are appreciated.
Description
===========
Illustrates a method to determine if a field has changed value on the Save event. This is important if there are dependency on the field data in other tables. For example, you could have checks in various tables to ensure that the deepest depth does not exceed the POINT.HoleDepth value. However, if the HoleDepth field is changed, the checks of these tables should be performed again. To avoid performing these checks if the HoleDepth has not changed, the method outlined by this sample can be used.
The checking procedure (FieldValueStatusFnEnum) makes use of the GintRecID field. This is a counter field automatically generated by ACCESS on saving each new record to the database. The value is a long integer, is always greater than zero, and is always unique within each table. On copying data from the table to the Input grid the program copies the GintRecID for each row to a hidden column. If a new record is added to the grid, this hidden field is assigned a zero value. If any field within the row is changed, the GintRecID field in the grid is made into the negative of its original value. The sample code checks the GintRecID value for each record and if it is zero returns that the row is new. If the grid GintRecID is positive, nothing in that row has changed. If the grid GintRecID is negative, something in the row has changed and the code then retrieves the original value for the desired field and compares it to the current value to see if it has changed.
The FieldValueStatusFnEnum procedure also returns an optional parameter which gives the current value saved in the database for the specified field. This is very important when checking to see if calculations must be regenerated in child tables when the parent record has changed. For example, if the HoleDepth field value has changed in the POINT table, all the child tables need to be checked. However, if the PointID has also changed you must search for child records with the currently saved PointID value, not the new value in the grid since the renames of the PointID do not occur until after the save event. See the "Point" procedure in GR011 for a sample on how this is done.
IMPORTANT NOTE:
Be warned that no field will appear to change during an import. The way import is handled is that first all the data are imported and then the save code is run. The same applies when running the Recalc Current Table command. Therefore, you may wish to run this block of code if a field has changed value or the current data entry mode is not manual entry. To that end, use the gINTRules.GridData.IsManualEntryMode property (requires gINT 8.1.015 or later). This returns True if in manual entry mode, False otherwise (import and recalc).
Usage
=====
This sample checks for changes to a field (Check Field) in the POINT table and reports whether the record associated with the field is new (has never been saved previously), the field is unchanged, or changed. To exercise the code, add a few records in the POINT table and save and then change the value of the "Check Field" and save. When actually using this facility you would perform some operation based on whether the record is new, the field is changed, or the field is unchanged.
Revision History
================
22 March 2007
Put in the "IsManualEntryMode" note under the Description section
--------------------------
11 May 2005
Initial upload
*************************************************
INCLUDED FILES:
GR010.GLB:
gINT Rules code modules:
GR010 Main
Point
GR010 COMMON PROCEDURES FieldValueStatusFnEnum
InitFieldsFnB
RecordsetClose
GR010.GPJ:
Sample project that makes use of the code modules.
*************************************************
INSTALLATION PROCEDURE:
Copy the files wherever you prefer. To see the gINT Rules code modules you must either merge the GLB into your library (Utilities:Lib Merge/Copy) or change to the included library (File:Change Library).
*************************************************