Use clipboard [3]: setcomponent, getcomponent

Source: Internet
Author: User
This example demonstrates the process of placing a component (tedit) on the clipboard and taking it out (put it on a tpanel.

The method for placing a clipboard is a process: setcomponent (component to be placed );
The method to retrieve is a function: getcomponent (specifying the owner and specifying the parent window): the handle of the component returned by the function.

Before extracting the clipboard, you 'd better determine whether it is a component in the current clipboard: hasformat (cf_component );

You must register the component class to be retrieved before removing the class, for example, registerclasses ([tedit]);

Preparation: Add tedit, tpanel, and three buttons to the form.
In this example:


 unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; type tform1 = Class (tform) button1: tbutton; button2: tbutton; button3: tbutton; edit1: tedit; Panel1: tpanel; Procedure handle (Sender: tobject); Procedure handle (Sender: tobject); Procedure button3click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses clipbrd; var OBJ: tcomponent; {used to accept the returned value of getcomponent} procedure tform1.button1click (Sender: tobject); begin clipboard. setcomponent (edit1); tbutton (sender ). caption: = 'copy'; end; Procedure tform1.button2click (Sender: tobject); begin registerclasses ([tedit]); If clipboard. hasformat (cf_component) Then OBJ: = clipboard. getcomponent (nil, Panel1); tbutton (sender ). caption: = 'pause'; end; Procedure tform1.button3click (Sender: tobject); begin if assigned (OBJ) Then obj. free; tbutton (sender ). caption: = 'delete'; end.

   

Generally, you should place the registerclasses (); Process in advance (at least avoid repeated execution), for example, in the form1.oncreate event;
It seems that everyone is used to advance to initialization.ProgramModify as follows:

 unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; type tform1 = Class (tform) button1: tbutton; button2: tbutton; button3: tbutton; edit1: tedit; Panel1: tpanel; Procedure handle (Sender: tobject); Procedure handle (Sender: tobject); Procedure button3click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses clipbrd; var OBJ: tcomponent; Procedure tform1.button1click (Sender: tobject); begin clipboard. setcomponent (edit1); tbutton (sender ). caption: = 'copy'; end; Procedure tform1.button2click (Sender: tobject); begin if clipboard. hasformat (cf_component) Then OBJ: = clipboard. getcomponent (nil, Panel1); tbutton (sender ). caption: = 'pause'; end; Procedure tform1.button3click (Sender: tobject); begin if assigned (OBJ) Then obj. free; tbutton (sender ). caption: = 'delete'; end; Initialization registerclasses ([tedit]); end.

   

In addition, the format of the clipboard has not been discussed in detail. Here we have a cf_component.

The format constants of more than a dozen clipboard types have been defined in windows, such as cf_bitmap and cf_text;
However, the cf_component here is customized by Delphi. We can guess that when necessary, we can also customize the format in the clipboard.

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.