Yes, use RTTI - here is a simple example:
type TDog = class (TComponent) private FColour: TColor; FSize: Integer;
published property Colour: TColor read FColor write FColor; property Size: Integer read FInteger write FInteger; end;
To clone this, you simply:
var stm: TTStream; dog1, dog2: TDog;
begin stm := TMemoryStream.Create; try stm.WriteComponent (dog1); stm.Seek (0, 0); stm.ReadComponent (dog2); finally stm.Free; end;
And BTW, I disagree that using RTTI breaks under different versions of Delphi - in fact, this code runs on *ALL* versions of Delphi! I wonder why Borland didn't write a generic Assign method using this!
Dennis.
From: "Neven MacEwan" <[EMAIL PROTECTED]> Dave
You could use RTTI, There are some good tutorials around
google Delphi RTTI
Neven
----- Original Message ----- From: <[EMAIL PROTECTED]> To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]> Sent: Wednesday, August 27, 2003 4:50 PM Subject: [DUG]: How do I copy the state of one object to another?
> Hi all
>
>
>
> I want to copy the state (variables) of one instance object of a class, to
> another instance object of the same class. Eg. Class TDog, instance Dog1
and
> Dog2. I could do the following:
>
> Dog2.Colour := Dog1.Colour;
>
> Dog2.Breed := Dog1.Breed; etc.
>
> But this seems a little silly. How do I do this in OO?
>
>
>
> If knowing more would be helpful, here's what I'm doing:
>
>
>
> I'm using ICS to connect to an smtp server and want to make multiple
> connections so that I can offload 4000 emails as quickly as possible,
> leaving the smtp server to send them out. (No I'm not a spammer, this is a
> report - email with pdf attachment).
>
>
>
> I've just run a test and I can paste multiple ICS components on my form
i.e.
> SmtpCli1, SmtpCli2, SmtpCli3, etc. And I can assign my email details into
> SmtpCli1 as my "holder' object. When I go to send, I see if SmptCli2 is in
a
> ready state - if so, I copy all of the details from SmtpCli1 to SmtpCli2
and
> send via Cli2. Else, I try SmtpCli3, etc. Using this method, and keeping 5
> sessions active, I found it sped up my job 5 fold - so seems worth it.
>
>
>
> So this all works but it's very manual with lots of code. How do I do this
> with OO elegance?
>
>
>
> Cheers
>
> Dave Jollie
> Developer, TOWER NZ IT
>
> *: 09 368 4259
> *: 09 306 6801
> *: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
> *: 46 Parnell Rd, Parnell, Auckland
>
>
>
>
--------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
_________________________________________________________________ Gaming galore at http://xtramsn.co.nz/gaming !
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
