PDA

View Full Version : copying class instances



peterbone
04-03-2004, 02:00 PM
If I set one class instance to another they share the same memory and so when the variables in one class change they both change. If I want to copy a class to another class instance so that it's independant do I have to set the variables and properties one at a time or is there a simpler solution?

Thanks

Peter

Useless Hacker
04-03-2004, 03:23 PM
If I want to copy a class to another class instance so that it's independant do I have to set the variables and properties one at a time or is there a simpler solution?Basically, yes, although you can make it easy for yourself by giving your classes an Assign() method. Descendants of TPersistent have this already, this would include any VCL components. If these are your own classes then you will have to implement your own methods for doing this.

peterbone
05-03-2004, 10:18 AM
They're my own classes so I'll write an assign procedure that will copy all the data to the specified instance. Thanks for the help.