Use of the Clipboard in Delphi [4]: If the control of the handle is copied together

Source: Internet
Author: User
Tags constructor

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.