PrimeRecord (prepare a record for adding:FileManager)

Top  Previous  Next

 

PrimeRecord( [suppress clear] ), VIRTUAL, PROC

PrimeRecord

Prepares a record for adding to the managed file.

suppress clear

An integer constant, variable, EQUATE, or expression that indicates whether or not to clear the record buffer. A value of zero (0 or False) clears the buffer; a value of one (1 or True) does not clear the buffer. If omitted, suppress clear defaults to zero (0).

The PrimeRecord method prepares a record for adding to the managed file and returns a value indicating success or failure. A return value of Level:Benign indicates success; any other return value indicates a problem.

Implementation:

PrimeRecord prepares the record by optionally clearing the record buffer, then calling the PrimeFields method to prime field values, and the PrimeAutoInc method to increment autoincrementing key values. If it succeeds, it returns Level:Benign (declared in ABERROR.INC), otherwise it returns the severity level of the last error it encountered. See Error Class for more information on severity levels.

The suppress clear parameter lets you clear or retain any other values in the record buffer.

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.PrimeRecord() !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.PrimeAutoInc PROCEDURE

CODE

!your custom code here

PARENT.PrimeAutoInc              !call the base class method

!your custom code here

See Also:     PrimeAutoInc, CancelAutoInc