Calling instance methods from outside a class hierarchy where they are defined
You can access PUBLIC instance methods from outside the class hierarchy of a given object by using an object reference to qualify the method name. When you invoke a PUBLIC method on an object that is overridden in the object’s class hierarchy, the AVM invokes the method in the most derived subclass that defines the method. There is no access to PRIVATE or PROTECTED methods from outside the class hierarchy.
This is the syntax to invoke a method from outside a class instance:
Element descriptions for this syntax diagram follow:
return-variable
If the method returns a value that is assigned, the name of the variable to put the return value into.
object-reference
An object reference whose class or interface type defines the method you are calling.
method-name
The name of a PUBLIC method defined somewhere in the class hierarchy of object-reference.
[parameter[ , parameter]...]
The parameters, if any, of the method. For more information on the syntax of parameter, see the Parameter passing syntax reference entry in OpenEdge Development: ABL Reference.
NO-ERROR
Optionally redirects error processing when the method is called as a statement.
The following example shows two sample classes, where a method in acme.myObjs.CustObj calls the public Alert( ) and InfoMsg( ) methods in an instance of acme.myObjs.Common.MsgObj that is created for the CustObj class:
USING acme.myObjs.*.
USING acme.myObjs.Common.*.
USING acme.myObjs.Interfaces.*.
CLASS acme.myObjs.CustObj INHERITS CommonObj IMPLEMENTS IBusObj:
...
DEFINE PRIVATE VARIABLE rCreditObj AS CLASS CreditObj NO-UNDO.
DEFINE PRIVATE VARIABLE rMsg AS CLASS MsgObj NO-UNDO. ...
CONSTRUCTOR PUBLIC CustObj( ):
...
rMsg = MessageHandler("acme.myObjs.CustObj"). END CONSTRUCTOR.
...
METHOD PUBLIC VOID CheckCredit ( ):
IF VALID-OBJECT(rCreditObj) THEN DO:
FOR EACH ttCustomer:
rCreditObj:SetCurrentCustomer (ttCustomer.CustNum).
rCreditObj:CheckCustCredit ( ).
/* Invokes the CustCreditLimit property GET accessor */
rMsg:InfoMsg (ttCustomer.Name + " is in good standing." + " Credit Limit has been increased to " + STRING(rCreditObj:CustCreditLimit)).
CATCH e AS Progress.Lang.AppError:
IF e:ReturnValue = "Over Limit" THEN
/* Invokes the CustCreditLimit property GET accessor */
rMsg:Alert(ttCustomer.Name + " is on Credit Hold." + " Balance exceeds Credit Limit of " + STRING (rCreditObj:CustCreditLimit)). ELSE
rMsg:Alert("Customer not found"). END CATCH.
END. /* FOR EACH ttCustomer */
END. /* VALID-OBJECT(rCreditObj) */
ELSE rMsg:Alert ("Unable to check credit"). END METHOD.
...
END CLASS.
In this case, rMsg is a private object reference data member that is initialized to an instance of MsgObj that is instantiated and returned from the MessageHandler( ) method of the CommonObj super class. (See the listing for this super class in Calling methods from inside a class hierarchy where theyare defined).
This MsgObj instance holds error and general message information specifically for the CustObj class that can be accessed using the Alert( ) and InfoMsg( ) methods implemented as follows:
CLASS acme.myObjs.Common.MsgObj:
DEFINE PRIVATE VARIABLE cObjType AS CHARACTER NO-UNDO.
CONSTRUCTOR PUBLIC MsgObj (INPUT pcObjType AS CHARACTER):
cObjType = pcObjType.
END CONSTRUCTOR.
METHOD PUBLIC VOID Alert (INPUT ErrorString AS CHARACTER): MESSAGE "Error in " cObjType "!" SKIP ErrorString VIEW-AS ALERT-BOX ERROR. END METHOD.
METHOD PUBLIC VOID InfoMsg (INPUT MsgString AS CHARACTER): MESSAGE MsgString VIEW-AS ALERT-BOX. END METHOD.