User Tools

Site Tools


primeautoinc_prepare_an_autoincremented_record_for_adding_.htm
Navigation:  ABC Library Reference > FileManager > FileManager Methods >====== PrimeAutoInc (prepare an autoincremented record for adding) C6H0009.jpg ====== Previous pageReturn to chapter overviewNext page

PrimeAutoInc, VIRTUAL, PROC

blk2blue.jpg

When a record is inserted, the PrimeAutoInc method prepares an auto-incremented record for adding to the managed file and handles any errors it encounters. If you want to provide an update form that displays the auto-incremented record ID or where RI is used to keep track of children, then you should use the PrimeAutoInc method to prepare the record buffer.

The TryPrimeAutoInc method provides a slightly different (manual) alternative for preparing autoincremented records.

The CancelAutoInc method restores the managed file to its pre-PrimeAutoInc state.

Implementation:

The PrimeRecord method calls PrimeAutoInc if the file contains an auto-incrementing key.

If PrimeAutoInc succeeds, it returns Level:Benign (declared in ABERROR.INC). If it ultimately 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.PrimeAutoInc() !prime auto inc Client columns

 POST(Event:CloseWindow)        !if prime fails, close down

END

OPEN(InsertWindow)

ACCEPT

 CASE FIELD()

 OF ?OK

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

!finish adding the new Client record

   IF Access:Client.Insert() = Level:Benign

     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.PrimeAutoInc PROCEDURE

CODE

!your custom code here

PARENT.PrimeAutoInc              !call the base class method

!your custom code here

See Also:     CancelAutoInc, PrimeRecord, TryPrimeAutoInc

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