User Tools

Site Tools


cancelautoinc_undo_primeautoinc_.htm
Navigation:  ABC Library Reference > FileManager > FileManager Methods >====== CancelAutoInc (undo PrimeAutoInc) C6H0009.jpg ====== Previous pageReturn to chapter overviewNext page

CancelAutoInc( [relation manager] ), VIRTUAL, PROC

blk2blue.jpg

CancelAutoInc Undoes any PrimeAutoInc action.
relation manager The label of the managed file's RelationManager object. If present, the “undo” action cascades to any related files. If omitted, the “undo” action does not cascade to related files.

The CancelAutoInc method restores the managed file, and optionally any related files, to their pre-PrimeAutoInc state, typically when an insert operation is cancelled. CancelAutoInc returns a value indicating its success or failure. A return value of zero (0 or Level:Benign) indicates success; any other return value indicates a problem.

Implementation:

The PrimeAutoInc method adds a “dummy” record when inserting records with autoincrementing keys. CancelAutoInc deletes this “dummy” record, and, if the relation manager parameter is present, CancelAutoInc deletes any children of the “dummy” record as well.

If CancelAutoInc 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 restore the files. 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            !prototype Access:File init

CancelAutoInc  PROCEDURE,VIRTUAL    !prototype CancelAutoInc

             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.PrimeRecord()   !prime Client record (autoinc)

 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.CancelAutoInc PROCEDURE        !restore file to pre-PrimeAutoInc

CODE

!your custom code here

PARENT.CancelAutoInc                        !call the base class method

!your custom code here

See Also:     PrimeAutoInc

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