[Lazarus] How to clone a component

patspiper patspiper at gmail.com
Thu Oct 4 09:45:15 CEST 2012

On 04/10/12 09:57, patspiper wrote:
> On 04/10/12 09:19, Mattias Gaertner wrote:
>> On Thu, 04 Oct 2012 00:33:07 +0300
>> patspiper <patspiper at gmail.com> wrote:
>>> Hi,
>>> What is the correct way to clone programmatically a component, ie 
>>> assign
>>> all its properties to another component of the same class (like the IDE
>>> designer's copy/paste)?
>>> The code below used to work in Delphi but does not with Lazarus (result
>>> is nil).
>>>       RegisterClass(TMyComponent);
>>>       Clipboard.SetComponent(MyComponent);
>>>       Result:= TMyComponent(Clipboard.GetComponent(Self, Self));
>> It should work in Lazarus too.
> It does not. It seems due to the fact that TClipboard.GetComponent 
> uses pcfComponent while TClipboard.SetComponent uses pcfCustomData 
> instead. Substituting pcfCustomData by pcfComponent did the job, but 
> then the copied (original) component seems to lose its events. I will 
> test further and report.
The copied (original) component's events are fine. However, it is the 
clone's events which are not as desired. Its methods code+data are equal 
to the original component's methods code+data whereas the data part 
should point to the clone itself for proper operation of the clone. Any 
ideas on how this should be handled?


More information about the Lazarus mailing list