OK, I thought it was fairly obvious what was on from my example.
A class variable contains a pointer to a piece of memory, initially this is
null but when you instantiate it using the New keyword (or CreateObject)
then a piece of memory is set aside for the class an the variable is set to
point to this piece of memory.
If you have a second variable which you set equal to an existing class
variable then you are copying the value of that variable, that is you are
copying the pointer to the memory which holds the class information. So you
aren't creating a copy of the class you are creating a copy of the pointer
to the class.
In order to create a copy of the class you would need to do one of two
things.
a)
instantiate a new class object
copy all the property values from the original to the new class
object
This isn't so difficult if you implement a properties collection on the
class
You could in theory
b)
instantiate a new class object
determine the length of memory containing the class data of the
original
copy the memory block of the original class data over the new class
data
This would involve a fair amount of API work.
--
Terry Kreft
"downwitch" <downwitch@gmail.com> wrote in message
news:1145074403.462091.300140@i40g2000cwc.googlegr oups.com...[color=blue]
> This is the point. The other posts don't show the key thing here,
> which is that even though you can set an Instance2 to _point to_ an
> Instance1, it's not because you say "make Instance1 nothing" that it
> truly goes away. In other words, it's not a clone, it's two pointers
> to the same single object.
>
> I would've posted real code, but (1) my class hierarchies are
> hydra-like, huge, and impossible, and (2) I am more interested in the
> theoretical wrongheadedness of why Access/VBA doesn't do this properly,
> and (less importantly) if this is common to classes in other
> programming environments. Besides, Albert nailed it with his simple
> addition to Terry's code: change one, you change the other, meaning
> there's one, not two. Still a slightly different question from why
> public instances of the same class collection can't be set to equal
> each other, but the two phenomena must be linked; if you could make a
> proper clone of an instance, then you could reasonably expect to make a
> proper clone of a part of an instance.
>
> Is this different from working with, say, two string variables, or is
> it all just pointers? At what point does something really get
> "created"?
>
>
> Albert D. Kallal wrote:[color=green]
> > In place of the = nothing...try changing the value of one of the
> > objects....you will see that the other changes....
> >
> > eg:
> >
> > Set MyFoo2 = MyFoo1
> > Debug.Print MyFoo1.Count, MyFoo2.Count
> >
> > MyFoo1.Add MyObj <--- add this
> >
> > Set MyFoo1 = Nothing
> >
> > Debug.Print MyFoo2.Count
> > Set MyFoo2 = Nothing
> >
> > you will get a value of 11 for the above last print....despite the first
> > object being set = nothing...
> >
> > When you set MyFoo1 = nothing...you are killing the pointer...but they[/color][/color]
both[color=blue][color=green]
> > are still the same copy.....
> >
> > Try adding one value to the first one BEFORE you do a set MyFoo1 =
> > nothing...and you will STILL find the 2nd instance will have that new
> > value...
> >
> > You have to write code to copy the class......
> >
> > --
> > Albert D. Kallal (Access MVP)
> > Edmonton, Alberta Canada
> >
pleaseNOOSpamKallal@msn.com
> >
http://www.members.shaw.ca/AlbertKallal[/color]
>[/color]