|
-
Aug 21st, 2001, 03:28 PM
#1
Thread Starter
New Member
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?
-
Aug 21st, 2001, 03:36 PM
#2
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.
-
Aug 21st, 2001, 03:46 PM
#3
Thread Starter
New Member
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.
-
Aug 21st, 2001, 07:42 PM
#4
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.
-
Aug 22nd, 2001, 07:16 PM
#5
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|