Try OpenEdge Now
skip to main content
Object-oriented Programming
Programming with Class-based Objects : Verifying the type and validity of an object reference : VALID-OBJECT function
 

VALID-OBJECT function

VALID-OBJECT is a built-in LOGICAL function that verifies the validity of an object reference. If the object has been deleted or equals the Unknown value (?), the reference is not valid.
This is the syntax for the VALID-OBJECT function:

Syntax

VALID-OBJECT( object-reference )
Element description for this syntax diagram follow:
object-reference
An object reference defined as any class or interface type.
If the object reference points to an object that is currently instantiated, VALID-OBJECT returns TRUE. Otherwise, it returns FALSE.
Note: VALID-OBJECT can also verify the validity of ABL handle-based objects. For more information, see OpenEdge Development: ABL Reference.
The acme.myObjs.Common.HelperClass sample methods make use of the VALID-OBJECT function to verify object references that might not have been initialized, depending on the order that the methods are invoked. (In fact, the sample order of execution guarantees valid object references. For more information on these samples, see Comparing constructs in classes and procedures. However, in a more complex application, the validity of object references at any given point might well be far from certain.)
For example, the following HelperClass fragment, the ReportOutput( ) method verifies that the object reference variable, rCustObj, has been set to reference a class instance before passing it as an OUTPUT parameter. In this application, rCustObj must be set by the ListNames( ) method before ReportOutput( ) can be run without error:
USING acme.myObjs.*.
USING acme.myObjs.Common.*.
USING acme.myObjs.Interfaces.*.

CLASS acme.myObjs.Common.HelperClass:
  DEFINE PRIVATE VARIABLE rCustObj AS CLASS CustObj NO-UNDO.
  DEFINE PRIVATE VARIABLE rMsg     AS CLASS MsgObj  NO-UNDO.
  ...

  CONSTRUCTOR PUBLIC HelperClass ( ):
    rMsg = NEW MsgObj ("acme.myObjs.Common.HelperClass").
  END CONSTRUCTOR.
  ...

  METHOD PUBLIC VOID ListNames (INPUT-OUTPUT prCustObj AS CLASS CustObj):
    ...
    rCustObj = prCustObj.
  END METHOD.

  METHOD PUBLIC VOID ReportOutput (OUTPUT prInterface AS CLASS IBusObj):
    /* Send the PRIVATE CustObj instance back to be printed */
    IF VALID-OBJECT(rCustObj) THEN
      prInterface = rCustObj.
    ELSE
      rMsg:Alert("Not a valid object").
  END METHOD.
  ...
END CLASS.