Weird object behaviour

  • Thread starter Thread starter Samuel Caparros
  • Start date Start date
S

Samuel Caparros

Hi group,

I have an app where I use a class defined by myself. I've been using it
normally until a few days ago. Every time I run a simple assignment...

Dim LocalObjectOfMyClass as New MyClass
LocalObjectOfMyClass = GlobalObjectOfMyClass

....all of a sudden, I'm getting an strange behaviour where, after this
point, every change I make to any property or variable in the local
object occurs in the global object as well. They seem somehow linked.

So. Is there something I should inmediately check or do I go dive
deeply into my code? I mean... May this be happening for any obvious
reason I am missing? Or does it have to be something wrong in my code?

Thanks
 
Looks expected to me.

You create a local object.
You then make this local object "point" to your global object.

Behind the scene objects are nothing else than pointers. When you assign an
object to another object you don't make a new "copy" the objet. You make
them point to the same location.

Patrice.
 
Behind the scene objects are nothing else than pointers. When you
assign an
object to another object you don't make a new "copy" the objet. You make
them point to the same location.

Whoa. Not such a strange behaviour then I guess. Ok, it's official now,
I'm a newbie.

Oh well, serious now. How do I make said "copy" of the object? I
mean...an exact duplicate I can later work "independently" with.

Thank you for answering, btw.
 
Try :
http://msdn.microsoft.com/library/d...rlrfsystemobjectclassmemberwiseclonetopic.asp

I f you have simple types it should be fairly simple (for a start you could
just copy properties ie Myobj.a=MyGernal.a:MyObj.b=MyGeneral.b etc...)


You may want to see :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbls7/html/vblrfVBSpec6_1.asp

The big picture may also help. Generally it's quite rare to need cloning
(here you could perhaps just have default values when the object is created,
from where are taken the properties of the global object ?)

Patrice


--
 
Back
Top