Use object references
- Last Updated: April 26, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
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 Define 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:
|