Use clipboard [1]: astext, settextbuf, and gettextbuf

Source: Internet
Author: User
The clipboard class tclipboard is defined in the clipbrd unit. Uses clipbrd is required before use;

 
Uses clipbrd; Procedure tform1.button1click (Sender: tobject); var clip: tclipboard; begin clip: = tclipboard. create; {create} clip. astext: = self. text; {put the Form title into the clipboard} showmessage (clip. astext); {read from the clipboard. The returned result is: form1} {because the clipboard is global, You can paste it elsewhere} clip. free; {release} end;

  

According to the convenience provided by Delphi, the above example can be simplified:

 
Uses clipbrd; Procedure tform1.button1click (Sender: tobject); begin clipboard. astext: = text; showmessage (clipboard. astext); {form1} end;

  

What is this clipboard? Is it the same type variable as screen?
The answer is no! Clipboard is just a function. It is a non-argument function and a global function defined in the clipbrd unit. It returns a variable of the tclipboard type. When I see the source code of this function, I feel that I have learned another skill and a very delicate idea.

In addition to the tclipboard. astext attribute, we can also use settextbuf to put the text into the clipboard and use gettextbuf to read the text in the clipboard.

 
Uses clipbrd; {use settextbuf} procedure tform1.button1click (Sender: tobject); begin clipboard. settextbuf (pchar (text); {according to parameter type requirements, need to convert} showmessage (clipboard. astext); {form1} end; {using gettextbuf is similar to using APIs. You need to give a buffer} procedure tform1.button2click (Sender: tobject); var arr: array [0 .. 255] of char; begin clipboard. astext: = text; clipboard. gettextbuf (ARR, length (ARR); showmessage (ARR); {form1} end; {if no buffer zone is provided, you have to apply for and release the memory.} procedure tform1.button3click (Sender: tobject); var PC: pchar; begin clipboard. astext: = text; getmem (PC, 256); {applied memory} clipboard. gettextbuf (PC, 256); showmessage (PC); {form1} freemem (PC); {release memory} 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.