 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
SD Guest
|
Posted: Thu Sep 21, 2006 8:12 am Post subject: Object copy |
|
|
Hi to all,
I'm new to patterns matter so I would like if you can
help me to a little question.
I stay to create a CAD/CAM program in which I would
like to use interface paradigm (I use MVP).
My objects (geometric objects, tools, lists) must have
possibility of copy, eg I can copy a complete object
contents in another object.
I know the TPersistent way (Assign) of VCL but I would
like to know if exist a corrispondent or similar concept
in patterns and Interface way.
Thank you...
--
Silverio, SiD Vicenza - Italy
Yahoo Messanger: SiDorDiS |
|
| Back to top |
|
 |
Joanna Carter [TeamB] Guest
|
Posted: Thu Sep 21, 2006 1:32 pm Post subject: Re: Object copy |
|
|
"SD" <nospawm (AT) please (DOT) it> a écrit dans le message de news:
451247ef (AT) newsgroups (DOT) borland.com...
| I'm new to patterns matter so I would like if you can
| help me to a little question.
|
| I stay to create a CAD/CAM program in which I would
| like to use interface paradigm (I use MVP).
|
| My objects (geometric objects, tools, lists) must have
| possibility of copy, eg I can copy a complete object
| contents in another object.
|
| I know the TPersistent way (Assign) of VCL but I would
| like to know if exist a corrispondent or similar concept
| in patterns and Interface way.
Either use Assign which takes an object to copy and assigns the values to
the object with the Assign method; or use Clone which returns the newly
populated object from an exitisn object.
function Clone: TMyType
{
Result := TMyType.Create;
Result.field1 := field1;
...
}
....or you can also create a copy constructor :
type
TMyType = class
private
// fields
public
constructor Create(other: TMyType);
function Clone: TMyType;
...
end;
constructor TMyType.Create(other: TMyType);
begin
inherited Create;
field1 := other.field1
...
end;
function TMyType.Clone: TMyType
{
Result := TMyType.Create(self);
}
Take a look at the Prototype design pattern
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer |
|
| Back to top |
|
 |
SD Guest
|
Posted: Thu Sep 21, 2006 6:36 pm Post subject: Re: Object copy |
|
|
Thanks for suggestions ! |
|
| Back to top |
|
 |
Jeroen Vandezande Guest
|
Posted: Mon Sep 25, 2006 8:39 pm Post subject: Re: Object copy |
|
|
Hi,
you could also use RTTI to make a more generic Object copy system:
http://www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm#CopyingPropertiesFromAComponentToAnother
the same can be done in Delphi.net with Reflection...
Best regards,
Jeroen Vandezande
"SD" <nospawm (AT) please (DOT) it> wrote in message
news:451247ef (AT) newsgroups (DOT) borland.com...
| Quote: | Hi to all,
I'm new to patterns matter so I would like if you can
help me to a little question.
I stay to create a CAD/CAM program in which I would
like to use interface paradigm (I use MVP).
My objects (geometric objects, tools, lists) must have
possibility of copy, eg I can copy a complete object
contents in another object.
I know the TPersistent way (Assign) of VCL but I would
like to know if exist a corrispondent or similar concept
in patterns and Interface way.
Thank you...
--
Silverio, SiD Vicenza - Italy
Yahoo Messanger: SiDorDiS
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|