THIS-OBJECT system reference
- Last Updated: June 30, 2014
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
THIS-OBJECT system reference
THIS-OBJECT is a system reference available
for use within an instantiated class. At run time, it returns the currently
running instance of the class as an object reference. It supports
several features:
- Allows a method of the class to pass a reference to the currently instantiated class hierarchy as a parameter or to return a reference to itself as a method return value.
- Allows you to call an instance method from within the class
hierarchy where the method is defined when the method name is a
reserved ABL keyword. To make such a method call, you use
THIS-OBJECTas an object reference to invoke the method. (This is the only situation where you can and must use theTHIS-OBJECTsystem reference to call a method.) - Allows you to access a variable data member or a class property from within the class hierarchy where the variable data member or class property is defined when the name is a reserved ABL keyword.
- In general, you can use
THIS-OBJECTas an object reference to call any instance method defined and available in the current hierarchy of a class as an aid to readability. For example, you might, as a convention, omitTHIS-OBJECTfor calling methods implemented by the current class definition, and use it as a documentary object reference for calling methods inherited by the current class definition.
THIS-OBJECT system reference
to access a static method.The following example shows a class, acme.myObjs.NewCustomer,
that inherits from the sample class acme.myObjs.CustObj:
|
This is not one of the installed sample classes, but is created
here to illustrate a use of the THIS-OBJECT system
reference. A call to its setNewCustObj( ) method
passes an object reference to the current instance of itself (THIS-OBJECT) to
the InitializeDate( ) method of the sample class, acme.myObjs.Common.HelperClass,
which timestamps itself, as shown here:
|
Because the THIS-OBJECT input parameter also represents
a subclass of the sample class, acme.myObjs.Common.CommonObj,
the InitializeDate( ) method can invoke
the updateTimestamp( ) method on the object
reference parameter (prObject) to timestamp the
object, which setNewCustObj( ) can reference
when InitializeDate( ) returns in the acme.myObjs.NewCustomer class
shown previously.
In the following example, a method of the Reserved class, DisplayToday( ),
calls the Now( ) method, also defined
in the class:
|
The name of the method is an ABL reserved keyword, which is the
name of the NOW function that also happens to be
invoked by the method in this example. If THIS-OBJECT is
not used to prefix the Now( ) function
call, ABL returns a compiler error indicating that it cannot recognize
the method.