CompObj()
This function compares two objects and tells you if they're identical. It does not tell you if they're really the same object.
Usage |
lMatch = COMPOBJ( oObject1, oObject2 ) |
Parameter |
Value |
Meaning |
oObject1 |
Object |
A reference to the first object to be compared. |
oObject2 |
Object |
A reference to the second object to be compared. |
lMatch |
.T. |
The two objects have the same list of properties and each property has the same value in the two objects. |
.F. |
The two objects do not completely match. |
Example |
* Create two forms o1 = CREATEOBJECT("Form") o2 = CREATEOBJECT("Form") ? COMPOBJ(o1, o2) && Returns .F. - No surprise since && their captions and names are different ? COMPOBJ(o1, o1) && Returns .T. - Again, no surprise * Make another reference to o1 o3 = o1 ? COMPOBJ(o1, o3) && Returns .T. - Good * Now watch this o2.Caption = o1.Caption o2.Name = o1.Name ? COMPOBJ(o1, o2) && Surprise - Returns .T. * So how do we find out if they point to the same object? * In VFP 6 and later, do it like this: ? o1 = o2 * Thanks to Ken Levy for the basic idea here, * useful in VFP 3 and VFP 5: cHoldCaption = o1.Caption o1.Caption = "XXX" ? COMPOBJ(o1, o3) && Still returns .T. - they're the same object ? COMPOBJ(o1, o2) && Returns .F. - they're different objects o1.Caption = cHoldCaption |
See Also |