7. Embedded SQL for Pascal : Pascal Variables and Data Types : Variable Usage : Pointer Variables
 
Share this page                  
Pointer Variables
A pointer variable references an object in the same way as in Pascal—the name of the pointer is followed by a caret (^):
:pointer_name^
Any further referencing required to fully qualify an object, such as a member of a pointed-to record, follows the usual Pascal syntax.
Syntax Notes:
1. The final object denoted by the pointer reference must be a scalar value (integer, floating-point or character string) or a record (if this is a legal simple record reference). There can be any combination of arrays, records or pointer variables, as long as the last object referenced has a scalar value or is a legal simple record.
2. The pointer reference is also used with file type variables (see the under in this chapter).
In the following example, a pointer to an employee record is used to load a linked list of values into the database table "employee":
exec sql begin declare section;
type
     EmpLink = ^EmployeeRec;
     EmployeeRec = record
            ename: packed array [1..20] of Char;
            eage: Integer;
            eidno: Integer;
            enext: EmpLink;
    end;
var
    elist: EmpLink;
exec sql end declare section;
    ...

while (elist <> nil) do
begin
    exec sql insert into employee (name, age, idno)
            values (:elist^.ename, :elist^.eage,
                 :elist^.eidno);
    elist := elist^.enext;
end;