Try OpenEdge Now
skip to main content
Object-oriented Programming
Programming with Class-based Objects : Instantiating and managing class-based objects : Accessing data members and properties : Referencing a public data member or property outside of the object that defines it
 
Referencing a public data member or property outside of the object that defines it
This is the syntax for referencing a PUBLIC instance data member or property from outside the object where it is defined:

Syntax

object-reference:data-member-or-property-name
Element descriptions for this syntax diagram follow:
object-reference
An object reference to a class instance whose class hierarchy defines the PUBLIC data member or property.
data-member-or-property-name
The name of a PUBLIC data member or property defined somewhere in the class hierarchy of object-reference.
For more information on accessing data members and properties, see the Class-based data member access and Class-based property access reference entries in OpenEdge Development: ABL Reference.
The following fragment from the acme.myObjs.CustObj sample class shows how you can access a PUBLIC property from outside the class instance (acme.myObjs.CreditObj) where it is defined:
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 ( ):
     rCreditObj = NEW CreditObj ( ).
    ...
    rMsg = MessageHandler("acme.myObjs.CustObj").
  END CONSTRUCTOR.

  ...

  METHOD PUBLIC VOID CheckCredit ( ):
    IF VALID-OBJECT(rCreditObj) THEN DO:
      FOR EACH ttCustomer:
        ...
        /* 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 */
    END.
    ELSE rMsg:Alert ("Unable to check credit").
  END METHOD.
  ...
END CLASS.
In the previous example, CustCreditLimit is a publicly readable property defined in the CreditObj class. However, its value is protected and can only be written from within its defining class hierarchy, because the property’s SET accessor is defined as PROTECTED. For more information on property accessors, see Definingproperties within a class.