Try OpenEdge Now
skip to main content
Object-oriented Programming
Programming with Class-based and Procedure Objects : Comparing handles and object references : Using object references

Using object references

Because classes in ABL are strongly-typed, ABL can check at compile-time if an object reference is valid. However, you can only reference an object of a compatible type. You can allow a single variable or a temp-table field to hold a reference to a variety of types using an object reference of an appropriate super class type. If you define a variable or a temp-table field as the class type Progress.Lang.Object, you can use it to store an object reference for any class type. If you want to access public data members, properties, methods, or events defined for the object as a subclass of the specified class type, you can cast the object reference to the type of that subclass (or lower in the class hierarchy). Otherwise, ABL catches any attempt to reference this subclass functionality as a compiler error. For more information on casting, see Object reference assignment and casting. In addition, ABL automatically garbage collects any class-based objects that you create; it is not necessary to explicitly delete them.
If you need to keep track of a collection of object references, for example for all the class instances running in a session, you can create a temp-table with a field of type Progress.Lang.Object. You can then store any object reference in that field. For more information on defining and using temp-table fields to reference class-based objects, see Defining an object reference field in a temp-table.
You can then use the temp-table to retrieve a Progress.Lang.Object reference and cast it to the appropriate class or you can use built-in Progress.Lang.Object methods to return information about the object. For example, to display the class type name for each object reference saved in a temp-table you might write the following code fragment:
  FIELD objRef AS CLASS Progress.Lang.Object.

FOR EACH ttObjHolder:
  MESSAGE objRef:GetClass( ):TypeName.