2. Language Elements : Variables : Reference Variables : How You Can Use Reference Variables
 
Share this page                  
How You Can Use Reference Variables
In OpenROAD, you can work with an object as a whole or with the attributes of the object. To manipulate the object as a single unit, use the name of the object's reference variable in your 4GL code.
For example, you can create a subform and specify its variable's class as a named user class. In your program you could then pass the values in the subform fields to a procedure simply by naming the variable as a procedure parameter.
In the following statement, customer is the name of the variable associated with a subform:
callproc update_cust (new = customer)
To access an individual attribute that belongs to an object, use the dot notation:
referencevariable_name.attribute_name
For example, assume that the subform previously described contained a field called Address. To reference that field, you would use:
customer.Address
In the following example, City and Street are attributes of class addr, and address is a declared reference variable:
address.City = 'Dallas';
x = address.Street;
callframe delete_old (address = address.City);
OpenROAD checks references to attributes by name and produces compiler errors if the variable's class does not contain those attributes. For example, given the following declarations:
a = Addr;
b = Addr;
tmp_char = varchar(30) not null;
Some valid references would be:
a.Street = tmp_char;
tmp_char = a.city;
Some invalid references would be:
a.Province = tmp_char;  /*  ERROR at compile time
                        ** because attribute 'province'
                        ** is not defined for class 'addr' */
a = null;
a.Street = tmp_char;    /*  ERROR at runtime because 'a' is
                        ** null, and does not reference
                        ** an object */