Microsoft KB Archive/126780

= PRB: Operator/Operand Type Mismatch When Comparing Two Objects =

Article ID: 126780

Article Last Modified on 2/12/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q126780



SYMPTOMS
The 'Operator/Operand Type Mismatch' error is returned when comparing two objects with the equal sign (=) operator.



CAUSE
The equal sign operator is used to compare character, logical, date, or numeric data. When the variable is an object reference, the equal sign is the assignment operator. The equal sign is used to create a reference to an object. It should not be used to compare objects.



WORKAROUND
Use the COMPOBJ function to compare two objects. The COMPOBJ function compares the properties of an object. It returns .T. if the properties and property values of two objects are identical.



STATUS
This behavior is by design.



MORE INFORMATION
The following example illustrates the use of the COMPOBJ function. It compares two objects created with the SCATTER NAME command. To run this example, copy the following code into a new program file (*.PRG) and run it. USE SYS(2004)+'\samples\data\customer' SCATTER NAME ocust1  && Creates a custom object ocust1 SCATTER NAME ocust2  && Creates a custom object ocust2 Ccompare=IIF(COMPOBJ(ocust1,ocust2),'True','False') * Test if objects are identical WAIT WINDOW "Compobject returned " + Ccompare NOTE: Classes have default properties that can be set when an object is instantiated. For example, when a form is instantiated, the values of CAPTION and NAME properties, among other properties, are set to a unique value. The following example illustrates the fact that COMPOBJ will return .F. if the values of these properties are not modified. Use the AMEMBERS function to verify the names and infer the values of properties, procedures, and member objects of an object. frmtest1= CREATEOBJECT('form') && Creates an instance of a form frmtest2 = CREATEOBJECT('form') && Creates an instance of a form Compare= IIF(COMPOBJ(frmtest1,frmtest2),'True','False') WAIT WINDOW "Compobj returned " + Compare * In this case, COMPOBJ returned .F. Some property values are not * identical

? frmtest1.name  && Returns Form, where n is a number ? frmtest2.name  && Returns Form, where n is a number frmtest1.name="mytest" frmtest2.name="mytest" ? frmtest1.caption && Returns Form, where n is a number ? frmtest2.caption && Returns Form, where n is a number

frmtest1.caption= "This is a test" frmtest2.caption= "This is a test" ?COMPOBJ(frmtest1,frmtest2) && Returns .T.

Additional query words: VFoxWin errmsg err msg

Keywords: kberrmsg kbcode KB126780

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.