Results 1 to 5 of 5

Thread: Copying Classes!!!

  1. #1

    Thread Starter
    New Member Maintex's Avatar
    Join Date
    Aug 2001
    Location
    England (Temporarily working in Germany)
    Posts
    4

    Unhappy Copying Classes!!!

    I am writing a large application that uses a few DLL's and within each of them are lots of classes. One class in particular acts as a collection of another type of class but occassionally, I want two of the elements in the collection to contain the same data, but when I say Set ClassA=ClassB (which are both of the same type) it creates a reference stating that ClassA should act as a reference to ClassB, and whenever anything is changed in either of them, the other is changed also! My question is whether or not there is a way to copy the data within the two classes without having to explicitly copy every value within the class?
    Maintex

  2. #2
    jim mcnamara
    Guest
    You can use a property bag to save (persist) the object to disk, then read it back again into another object. If the object has a lot of properties, this is easier and less error-prone than trying to
    do it the long way in code.

  3. #3

    Thread Starter
    New Member Maintex's Avatar
    Join Date
    Aug 2001
    Location
    England (Temporarily working in Germany)
    Posts
    4
    Thankyou for replying, that is a great idea, but unfortunately it requires the class to be Multiuse or above, and currently it is Public and Not Creatable, and it won't work like that. I would prefer to keep it like this, but if there is no other solution, I'll use the property bag.
    Maintex

  4. #4
    jim mcnamara
    Guest
    By the way, when you do Set obj1 = obj2,

    what you are creating is an object pointer (obj1 in this example). Anything done to obj1 is reflected in obj2, and anything changed in obj2 shows up in obj1. This is because you only have one object, with two references.

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I had the same problem a few weeks ago, and with a lot of research, there is no easy way around it. I basically just wrote a "Clone" routine, that copied the contents of one object, to the cloned object. It's really not to painful..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width