Weird object behaviour

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Samuel Caparros

    Weird object behaviour

    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 LocalObjectOfMy Class as New MyClass
    LocalObjectOfMy Class = GlobalObjectOfM yClass

    ....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

  • Patrice

    #2
    Re: Weird object behaviour

    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.

    --

    "Samuel Caparros" <monroe@ciudadp aragon.com> a écrit dans le message de
    news:1107792574 .139421.89790@g 14g2000cwa.goog legroups.com...[color=blue]
    > 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 LocalObjectOfMy Class as New MyClass
    > LocalObjectOfMy Class = GlobalObjectOfM yClass
    >
    > ...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
    >[/color]


    Comment

    • Samuel Caparros

      #3
      Re: Weird object behaviour

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

      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 "independen tly" with.

      Thank you for answering, btw.

      Comment

      • Patrice

        #4
        Re: Weird object behaviour

        Try :


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


        You may want to see :


        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


        --

        "Samuel Caparros" <monroe@ciudadp aragon.com> a écrit dans le message de
        news:1107798299 .723215.8860@f1 4g2000cwb.googl egroups.com...[color=blue][color=green]
        > > Behind the scene objects are nothing else than pointers. When you[/color]
        > assign an[color=green]
        > > object to another object you don't make a new "copy" the objet. You[/color]
        > make[color=green]
        > > them point to the same location.[/color]
        >
        > 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 "independen tly" with.
        >
        > Thank you for answering, btw.
        >[/color]


        Comment

        Working...