Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How do I compare this?
Message
From
09/03/1998 07:52:58
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
09/03/1998 02:53:10
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00083306
Message ID:
00083325
Views:
21
>Help!
>I have stored the value of this to a custom property on my form which I then compare, using;
>
>if thisform.surrounded==this
>
>basically checking that the original value is either the same or not.
>This code I should add is in the mousemove event of my controls.
>
>Anyone keen to tell me the *right* way? < S >
>
>Cheers
>John
John,
Since you use "this" then it's an object compare. COMPOBJ() compares two objects and tells you if they're identical. It doesn't tell you if they're really the same object (Hacker's Guide to VFP 3.0 - info is from there and code following unmodified).
* 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
* Thanks to Ken Levy for the basic idea here:
cHoldCaption = o1.caption
o1.caption = "XXX"
?compobj(o1,o3)    && Still returns .t. - they're the same
?compobj(o1,o2)    && Returns .f. - they're different
o1.caption = cHoldCaption
So extended implementation :
if lExactlySame(thisform.surrounded,this)
..
endif

function lExactlySame
lparameters o1, o2
cHoldName = o1.name
o1.name = "xxx"
rVal = compobj(o1,o2)
o1.name = cHoldName
return rVal
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform