Use of the Clipboard in Delphi [2]: Assign, Hasformat

Source: Internet
Author: User

Preparatory work:

Place a tpanel on the form; Put a timage on the Tpanel; Another three buttons are required.

This example effect chart:

First edition code:

Unit Unit1; Interface uses Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Extctrl
 
S
    Type TFORM1 = Class (Tform) Button1:tbutton;
    Button2:tbutton;
    Button3:tbutton;
    Panel1:tpanel;
    Image1:timage;
    Procedure Button1Click (Sender:tobject);
    Procedure Button2click (Sender:tobject);
  Procedure Button3click (Sender:tobject);
 
End
 
var Form1:tform1;
 
Implementation {$R *.DFM} uses CLIPBRD;
Procedure Tform1.button1click (Sender:tobject);
  Begin Image1.left: = 0;
  Image1.top: = 0;
  Panel1.autosize: = True;
  Image1.autosize: = True;
 
  Image1.Picture.LoadFromFile (' c:\temp\test.bmp '); TButton (Sender).
Caption: = ' import ';
 
End
Procedure Tform1.button2click (Sender:tobject); Begin Clipboard.assign (image1.picture);
  {Put the picture in the Image1 into the clipboard}
 
  {Now can be pasted in the image software, you can try it with a Windows drawing board} TButton (Sender).
Caption: = ' copy ';
 
End
Procedure Tform1.button3click (Sender:tobject); var Bit:tbitmap; {Prepare to use aTbitmap from the Clipboard to end the picture} X,y:integer;
  Begin bit: = Tbitmap.create; Bit.               Assign (Clipboard); {Get from the Clipboard} x: = Panel1.width + panel1.left * 2;
  {X,y is ready to paste position on the form} y: = Panel1.top;              Canvas.draw (x, y, bit); {Paste is to draw out the bit.}
 
  Free; TButton (Sender).
Caption: = ' paste ';
 
End End.

But now the program still has a loophole: if there is nothing in the Clipboard, what to paste? If the Clipboard is not a picture, how do I paste it?

In fact, we only use the Tclipboard.hasformat function to judge the Clipboard is not a picture on the line.

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.