PDA

Click to See Complete Forum and Search --> : 2 Reference of one Instance


Stonebrook
Feb 13th, 2001, 08:31 AM
How can i compare 2 refernces of One Instance of an Object

Example:

Set objA = CreateObject ("ClassString.Class")
Set objB = ObjA

If ObjB = ObjA Then MsgBox ("OK")

etc...

why does this compare of 2 Instances not work ???

Is there a other way ??


thanks
Stonebrook

simonm
Feb 13th, 2001, 08:50 AM
If there is a property that generates a unique identifier everytime an instance is created then you can compare these.

If not, it could be tricky. Change a property value on one and then see if it changes on the other?

Feb 13th, 2001, 02:47 PM
it doesnt work because you are asking if two pointers
are the value..since A points to the data and B points to A they will not be the same...

i know somebody will say VB doesnt use pointers...
but it actually uses a vtable of addresses and thats
pretty much the same thing..

in "C" it's called indirect reference...

since you are assigning these pointers to objects...

A -> object
B -> A

this would work.. A.Property = cow
B.Property = cow

otherwise A = object address
B = A address

that was easy huh....

Stonebrook
Feb 14th, 2001, 02:09 AM
... what happens with the Refernce of Object B if i free Object A ??

simonm
Feb 14th, 2001, 02:45 AM
Because B is NOT pointing to A. B is pointing to the object. If you remove A, B will still be referencing the same object.