If you copy to the Clipboard along with the child controls, you need to define a new type.
For example, include a tedit in a tpanel; To replicate with Tedit, you need to tpanel a class from Tpanel (for example, Tmypanel) and include Tedit in the new class.
Run Effect chart:
Units of the Tmypanel class:
unit MyPanel;
interface
uses Classes, StdCtrls, ExtCtrls;
type
TMyPanel = class(TPanel)
Edit1: TEdit;
constructor Create(AOwner: TComponent); override;
end;
implementation
{ TMyPanel }
constructor TMyPanel.Create(AOwner: TComponent);
begin
inherited;
Edit1 := TEdit.Create(Self);
Edit1.Parent := Self;
Edit1.Left := 10;
Edit1.Top := 10;
RegisterClasses([TMyPanel]); {在这里就给注册了}
end;
end.
Test Unit:
Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls;
Type
TForm1 = Class (Tform)
Button1:tbutton;
Button2:tbutton;
Procedure Formcreate (Sender:tobject);
Procedure Button1Click (Sender:tobject);
Procedure Button2click (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses CLIPBRD, Mypanel;
Var
Obj:tcomponent;
Pnl:tmypanel;
Procedure Tform1.formcreate (Sender:tobject);
Begin
PNL: = Tmypanel.create (Self);
PNL. Parent: = Self;
PNL. Edit1.text: = ' be copied together ';
Button1.caption: = ' copy ';
Button2.caption: = ' paste ';
End
Procedure Tform1.button1click (Sender:tobject);
Begin
Clipboard.setcomponent (PNL);
End
Procedure Tform1.button2click (Sender:tobject);
Begin
If Clipboard.hasformat (cf_component) Then
Begin
Obj: = Clipboard.getcomponent (self, self);
Tmypanel (obj). Left: = 20;
Tmypanel (obj). Top: = 60;
End
End
End.