|
In the
wider world, this is known as 'cloning'.
Just
to complicate things you can have both shallow and deep
cloning.
A
shallow clone will create a copy of an object along with copies of all it's
'value' properties (things like strings, integers, etc.), but will only copy
references to any contained objects (so two shallow clones would refer to the
same instance of a third object).
A deep
clone will create a copy of an object along with copies of all it's value
properties, but will also recursively clone any contained objects (so deep
cloning an object which has a reference to another object will result
in 4 objects - each of the two parent objects will have it's own instance of the
child object).
Google
is your friend, and will provide you with a multitude of
references.
Peter's right with the reference to Delphi's way of doing simple cloning
using Assign.
Having
a 'copy constructor' is another way of doing the same thing. You write a
constructor for your class which has one parameter - another instance of the
same class. Inside your constructor you simply copy all the values over
from the parameter object to the new object you're
constructing.
HTH,
Conor
|
- [DUG]: How do I copy the state of one object to another? Dave . Jollie
- Re: [DUG]: How do I copy the state of one object to ... Neven MacEwan
- Re: [DUG]: How do I copy the state of one object to ... ping_delphilist
- Re: [DUG]: How do I copy the state of one object to ... Phil Middlemiss
- RE: [DUG]: How do I copy the state of one object to ... Conor.Boyd
- RE: [DUG]: How do I copy the state of one object to ... Dave . Jollie
