BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Object copy

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
SD
Guest





PostPosted: Thu Sep 21, 2006 8:12 am    Post subject: Object copy Reply with 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
Joanna Carter [TeamB]
Guest





PostPosted: Thu Sep 21, 2006 1:32 pm    Post subject: Re: Object copy Reply with quote



"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





PostPosted: Thu Sep 21, 2006 6:36 pm    Post subject: Re: Object copy Reply with quote



Thanks for suggestions !
Back to top
Jeroen Vandezande
Guest





PostPosted: Mon Sep 25, 2006 8:39 pm    Post subject: Re: Object copy Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.