4. Working with Classes : How You Can Reference Objects
 
Share this page                  
How You Can Reference Objects
In OpenROAD, you do not reference objects directly. Instead, every object is associated with a reference variable. A reference variable is a variable that points to an object of a given class, letting you access the value of an object. For example, to manipulate a value stored in a field, you use the field's variable name directly:
acct_balance = 1000.00
However, to manipulate the field as an object, accessing such characteristics as its background color or executing one of its methods, you must access the field's reference variable. A reference variable lets you manipulate all of the attributes and methods of that field's class. Whereas the variable storing the field's value is scalar, reference variables are pointers to compound data structures that reference all the object's attributes and methods.
A reference variable does not store an object's data values. Instead, when you reference the reference variable, OpenROAD uses the values stored in the corresponding object's attributes. If there is no corresponding object, the value of the reference variable is null.
An object's properties are stored in the attributes that define the object. Attributes can be:
Simple data items, such as background color
Other reference variables, such as an image used for a button label
Dynamic array variables, such as the ChildFields array associated with a composite field
In 4GL code, you can work with individual attributes of the object (such as the background color) or with the object as a whole. Working with the whole object allows you, for example, to retrieve a row from a database table and assign all values from the row to a single object. You can then easily map the object to a set of fields in a subform or a row in a table field, or pass it as a unit to a procedure.
The following is an illustration of a single object of the VIDEO_ROW user class. It illustrates referencing an object as a whole. It shows a reference variable called video, which stores a single object from the user class VIDEO_ROW. Each object of the user class represents a row of data stored in the video database table.
When you declare a reference variable, you specify its class, and optionally specify its default value. The class defines the attributes in the associated object. OpenROAD automatically creates an object of the specified class when you create or declare the reference variable unless you also specify that it defaults to null.
The following example demonstrates creating the video reference variable for the VIDEO_ROW user class:
initialize ( )=
declare
    video = VIDEO_ROW default null;
enddeclare
begin
...
To reference an individual attribute of the VIDEO_ROW object, such as a video's title, use the following dot notation:
video.title