8.1.3 Retrieving and Referencing Objects

You can retrieve objects with functions, properties, and methods. To reference a retrieved object, you must assign it to an object variable.

Retrieving Objects

The most direct way to retrieve a Session object is with the GetObject function, which retrieves a reference to an object from a file. For example, the following expression retrieves a Session object from the file Session1.EDP.

GetObject("Session1.EDP")

Although this expression does not include a reference to the System object, which is at the top level of the object hierarchy, it nonetheless creates a System object before retrieving the Session object.

Each InfoConnect Enterprise object has properties that return references to other objects. For example, the expression System.Sessions returns a reference to a Sessions collection object. The expression Session.Screen returns a reference to a Screen object.

Some objects also include methods that return references to objects. For example, the expression Screen.Area(1,1,10,80) returns an Area object corresponding with an area of the screen.

Referencing Objects

To control a retrieved object, you must assign an object reference to an object variable. First, declare an object variable with a Dim, Static, or Global statement. Next, use the Set statement to assign to the object variable a reference to the object.

NOTE:The Set statement assigns an object reference to a variable, not a copy of the object. Therefore, more than one object variable can refer to the same object. Any change to an object affects all variables that reference that object.

In the following lines, two object variables are declared. In the first Set statement, the GetObject function returns a reference to a Session object, assigned to the object variables Ses1. In the second Set statement, the Screen property of Ses1 is used. A reference to a Screen object is returned and assigned to the object variable SessionScreen.

Dim Ses1 As Object, SessionScreen As Object
Set Ses1 = GetObject("Session1.EDP")
Set SessionScreen = Ses1.Screen

Object variables are necessary for referencing objects. However, for objects that must be retrieved but not referenced, it is more efficient to use a compound statement rather than assigning an object to a variable.