Navigation: ABC Library Reference > BufferedPairsClass > BufferedPairsClass Methods >====== AddPair (add a field pair:BufferedPairsClass) ====== | |
AddPair( left, right ), VIRTUAL
AddPair | Adds a field pair to the RealList property. |
left | The label of the “left” field of the pair. The field may be any data type, but may not be an array. |
right | The label of the “right” field of the pair. The field may be any data type, but may not be an array. |
The AddPair method adds a field pair to the RealList property. A third “buffer” field is supplied for you. You may use this third “buffer” as an intermediate storage area (a save area).
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 BufferedPairs object. The other BufferedPairs methods then operate on this virtual structure.
Implementation:
AddPair assumes the RealList property has already been created by Init or by some other method.
By calling AddPair for a series of fields (for example, the corresponding fields in a RECORD and a QUEUE), you effectively build three virtual structures containing the fields and a (one-to-one-to-one) relationship between the structures.
Example:
INCLUDE('ABUTIL.INC') !declare BufferedPairs Class
Fields &BufferedPairsClass !declare BufferedPairs reference
Customer FILE,DRIVER('TOPSPEED'),PRE(CUST),CREATE,BINDABLE
ByNumber KEY(CUST:CustNo),NOCASE,OPT,PRIMARY
Record RECORD,PRE()
CustNo LONG
Name STRING(30)
Phone STRING(20)
END
END
CustQ QUEUE
CustNo LONG
Name STRING(30)
Phone STRING(20)
END
CODE
Fields &= NEW BufferedPairsClass !instantiate BufferedPairs object
Fields.Init !initialize BufferedPairs object
Fields.AddPair(CUST:CustNo, CustQ.CustNo)!establish CustNo pair
Fields.AddPair(CUST:Name, CustQ.Name) !establish Name pair
Fields.AddPair(CUST:Phone, CustQ.Phone) !establish Phone pair