Navigation: ABC Library Reference > FileManager > FileManager Methods >====== TryInsert (try to add a new record) ====== | |
TryInsert, PROC
The TryInsert method adds a new record to the file, making sure the record is valid, and automatically incrementing key values as required. The TryInsert method does not attempt to handle errors.
The Insert method provides a slightly different (automatic) alternative for adding records.
Implementation:
TryInsert tries to add 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 add the record. See Error Class for more information on severity levels. Although TryInsert calls the PrimeAutoInc method if needed to set auto incrementing field, it clears the AutoIncDone property, so a call later to CancelAutoInc will not remove the autoinc record unless a call to either PrimeRecord or PrimeAutoInc is is done BEFORE a call to TryInsert.
Return Data Type: BYTE
Example:
PROGRAM
INCLUDE('ABFILE.INC') !declare FileManager class
MAP . !program map
GlobalErrors ErrorClass !declare GlobalErrors object
Access:Client CLASS(FileManager) !derive Access:Client object
END
InsertWindow WINDOW('Add a new Client'),AT(,,159,73),IMM,SYSTEM,GRAY
PROMPT('&Name:'),AT(8,20),USE(?CLI:Name:Prompt)
ENTRY(@s0),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
END
CODE
!program code
ACCEPT
CASE FIELD()
OF ?OK
IF EVENT() = Event:Accepted !on OK button
IF Access:Client.TryInsert() = Level:Benign !add the new Client record
POST(Event:CloseWindow) !if add succeeds, close down
ELSE !if add fails
Access:Client.Throw(Msg:InsertFailed) !handle the error
Access:Client.CancelAutoInc !restore the file
CYCLE !and start over
END
END
!more code
See Also:Insert, PrimeRecord , ADD