Try OpenEdge Now
skip to main content
Object-oriented Programming
Programming with Class-based Objects : Comparing objects
 

Comparing objects

You can compare two object references for equality using the equals operator (=), which checks if two object references are actually referencing the same object. The object references can be equal even if the object references have been defined for different classes in the class hierarchy. If the two object references are defined for different classes, they are also equal if they are both set to the Unknown value (?).
Note: You can also perform the same object reference comparison using the Equals( ) method on Progress.Lang.Object. For more information, see Using the root class: Progress.Lang.Object.
The following example demonstrates the use of the equal operator using the two object references stored in rSuper and rSubClass:
DEFINE VARIABLE rSubClass AS CLASS SubClass   NO-UNDO.
DEFINE VARIABLE rSuper    AS CLASS SuperClass NO-UNDO.

rSubClass = NEW SubClass ( ).
rSuper    = rSubClass.

IF rSuper = rSubClass THEN
  MESSAGE "they are the same".
The MESSAGE statement will indeed be executed, demonstrating that rSuper and rSubClass are equal even though they reference different class types in the class hierarchy.