Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread How to clone or duplicate an object?
Mon, Oct 8 2012 6:12 AMPermanent Link

Peter

Hello,

is it possible to clone or duplicate an object (e.g. a TPanel)?

Thanks in advance & Greetings ... Peter
---
Sorry for my weird english
Mon, Oct 8 2012 11:35 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Peter,


Am I missing something... How about Copy/Paste?

--
Fernando Dias
[Team Elevate]
Mon, Oct 8 2012 11:52 AMPermanent Link

Uli Becker

Fernando,

I didn't even dare to ask. Smile
It must be something more complicated.

Uli
Mon, Oct 8 2012 12:49 PMPermanent Link

Peter

Hello Fernando,

> Am I missing something... How about Copy/Paste?

LOL, Uli is right: I mean how to clone or duplicate an object
*programmatically*. Wink

something like this:

myNewPanel := myExistingPanel.Clone();

Greetings ... Peter
Mon, Oct 8 2012 1:12 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Peter


How about the same way you'd do it in Delphi

myNewPanel := TPanel.Create(self);
myNewPanel.Height := myExistingPanel.Height;
....
....

Roy Lambert [Team Elevate]
Mon, Oct 8 2012 4:58 PMPermanent Link

Mark Brooks

Slikware

Avatar

<<is it possible to clone or duplicate an object (e.g. a TPanel)>>

I use this technique a lot, but only in classes that I have defined myself. If I often find myself wanting to create a new instance based on an existing instance then I add a CopyFrom method. For example:

TMyClass = class
public
 procedure CopyFrom(const AClass: TMyClass);
end;

The code in CopyFrom simply copies across the elements that make sense in the context of a "copy from" action. Not sure if this is what you mean?

Mark
Image