User Tools

Site Tools


insert_add_a_new_record_.htm
Navigation:  ABC Library Reference > FileManager > FileManager Methods >====== Insert (add a new record) C6H0009.jpg ====== Previous pageReturn to chapter overviewNext page

Insert, PROC

blk2blue.jpg

The Insert method adds a new record to the file, making sure the record is valid, and automatically incrementing key values as required. The Insert method handles any errors that occur while adding the record.

The TryInsert method provides a slightly different (manual) alternative for adding new records.

Implementation:

If Insert succeeds, it returns Level:Benign (declared in ABERROR.INC). If it fails, it returns the severity level of the last error it encountered while trying to add 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

GlobalErrors ErrorClass                !declare GlobalErrors object

Access:Client CLASS(FileManager)       !derive Access:Client object

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

      END CODE

!program code

ACCEPT

 CASE FIELD()

 OF ?OK

  IF EVENT() = Event:Accepted               !on OK button

   IF Access:Client.Insert() = Level:Benign !add the new Client record

    POST(Event:CloseWindow)                 !if add succeeds, close down

   ELSE                                     !if add fails

    Access:Client.CancelAutoInc             !restore the file

    CYCLE                                   !and start over

   END

  END

!more code

See Also:     TryInsert, PrimeRecord

insert_add_a_new_record_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1