AddItem (add a field pair from one source field) 

Top  Previous  Next

 

AddItem( left )

AddItem

Adds a field pair to the List property from one source field.

left

The address of the "left" field of the pair. The field may be any data type, but may not be an array.

The AddItem method adds a field pair to the List property from one source field. The "right" field is supplied for you, and initially contains a copy of the data in the "left" field.

The fields need not be contiguous in memory, nor do they need to be part of a structure. Therefore you can build a virtual structure simply by adding a series of otherwise unrelated fields to a FieldPairs object. The other FieldPairs methods then operate on this virtual structure.

Implementation: AddItem assumes the List property has already been created by Init or by some other method.

By calling AddItem for a series of fields, you effectively build two virtual structures containing the fields--the "Left" is the original fields and the "Right" contains a copy of the data in the original fields at the time you call AddItem.

Example:

INCLUDE('ABUTIL.INC')       !declare FieldPairs Class

DKeyPair FieldPairsClass     !declare FieldPairs reference

 

Org   FILE                   !declare a file

DptKey  KEY(Dept,Grade)      !declare a multicomponent key

    RECORD

Dept    SHORT

Mgr     SHORT

Grade   SHORT

   ..

CODE

DKeyPair.Init               !initialize FieldPairs object

DKeyPair.AddItem(Org:Dept)  !add Dept (left) and a copy of Dept (right)

DKeyPair.AddItem(Org:Grade  !add Grade (left) and a copy of Grade (right)

!some code

DKeyPair.AssignLeftToRight  !Save the current key fields' values

SET(Org:DptKey,Org:DptKey)  !position the file

NEXT(Org)                   !retrieve (hopefully) a specific record

IF ERRORCODE() OR |         !confirm retrieval of matching record by

  ~DKeyPair.Equal()         !comparing retrieved key values with saved values

 MESSAGE('Record not found!')

END

See Also     Init, List