Navigation: ABC Library Reference > FileManager > FileManager Methods >====== TryPrimeAutoInc (try to prepare an autoincremented record for adding) ====== | |
TryPrimeAutoInc, VIRTUAL, PROC
When a record is Inserted, the TryPrimeAutoInc method prepares an autoincremented record for adding to the managed file. The TryPrimeAutoInc method does not handle any errors it encounters.
The PrimeAutoInc method provides a slightly different (automatic) alternative for preparing autoincremented records.
The CancelAutoInc method restores the managed file to its pre-TryPrimeAutoInc state.
Implementation:
TryPrimeAutoInc tries to prime the record. If it succeeds, it returns Level:Benign (declared in ABERROR.INC). If it fails, it returns the severity level of the error it encountered while trying to prime the record. See Error Class for more information on severity levels.
Return Data Type: BYTE
Example:
PROGRAM |
INCLUDE('ABFILE.INC') !declare FileManager class |
MAP !program map |
END |
GlobalErrors ErrorClass !declare GlobalErrors object |
Access:Client CLASS(FileManager) !derive Access:Client object |
Init PROCEDURE !initialize Access:File object |
PrimeAutoInc PROCEDURE,VIRTUAL !prepare new record for adding |
END |
Client FILE,DRIVER('TOPSPEED'),PRE(CLI),CREATE,BINDABLE,THREAD |
IDKey KEY(CLI:ID),NOCASE,OPT,PRIMARY |
Record RECORD,PRE() |
ID LONG |
Name STRING(20) |
StateCode STRING(2) |
END |
END |
InsertWindow WINDOW('Add a new Client'),AT(,,159,73),IMM,SYSTEM,GRAY |
PROMPT('&Name:'),AT(8,20),USE(?CLI:Name:Prompt) |
ENTRY(@s20),AT(61,20,84,10),USE(CLI:Name),MSG('Client Name'),REQ |
PROMPT('State Code:'),AT(8,34),USE(?CLI:StateCode:Prompt) |
ENTRY(@s2),AT(61,34,40,10),USE(CLI:StateCode),MSG('State Code') |
BUTTON('OK'),AT(12,53,45,14),USE(?OK),DEFAULT |
BUTTON('Cancel'),AT(82,53,45,14),USE(?Cancel) |
END |
CODE |
GlobalErrors.Init !initialize GlobalErrors object |
Access:Client.Init !initialize Access:Client object |
Access:Client.Open !open the Client file |
IF Access:Client.TryPrimeAutoInc() !prime Client record |
POST(Event:CloseWindow) !if prime fails, close down |
END |
OPEN(InsertWindow) |
ACCEPT |
CASE FIELD() |
OF ?OK |
IF EVENT() = Event:Accepted !on OK button |
IF Access:Client.Insert() = Level:Benign !finish adding the new Client record |
POST(Event:CloseWindow) !if add succeeds, close down |
ELSE !if add fails |
SELECT(?CLI:Name:Prompt) !select client name field |
CYCLE !and start over |
END |
END |
OF ?Cancel |
IF EVENT() = EVENT:Accepted !on Cancel button |
Access:Client.CancelAutoInc !restore Client to pre-PrimeRecord |
POST(Event:CloseWindow) !close down |
END |
EMD |
END |
Access:Client.Close !close the Client file |
Access:Client.Kill !shut down the Access:Client object |
GlobalErrors.Kill !shut down the GlobalErrors object |
RETURN |
Access:Client.TryPrimeAutoInc PROCEDURE |
ReturnValue BYTE,AUTO |
CODE |
!Custom code goes here |
ReturnValue = PARENT.TryPrimeAutoInc() |
!Custom code goes here |
RETURN ReturnValue |
See Also: CancelAutoInc, PrimeAutoInc