RAD Studio VCL Reference
|
Deletes the contents of the clipboard.
procedure Clear; virtual;
virtual __fastcall Clear();
Call Clear to empty the clipboard.
Clear is called automatically by TClipboard operations that add data to the clipboard.
C++ Examples:
/* This example uses a button and an TEdit on a form. When the user clicks the button, any text on the clipboard is pasted into the TEdit. If there is no text on the clipboard, a message box appears. Note: To use this example, you must add Clipbrd to the uses clause. Load the Clipboard by performing a copy in any application. */ #include <Clipbrd.hpp> void __fastcall TForm1::Button1Click(TObject *Sender) { if (Clipboard()->HasFormat(CF_TEXT)) { Edit1->Text = Clipboard()->AsText; Clipboard()->Clear(); } else MessageDlg( "There is no text on the Clipboard", mtInformation, TMsgDlgButtons() << mbOK, 0); }
/* The following code draws a bitmap image from the Clipboard when a button is pressed. The SaveToClipboard button must be selected before the LoadFromClipboard button in order to place the icon on the clipboard. */ #include <Clipbrd.hpp> #include <memory> //for STL auto_ptr class void __fastcall TForm1::Button1Click(TObject *Sender) { TClipboard *cb = Clipboard(); if (cb->HasFormat(CF_BITMAP)) { std::auto_ptr<Graphics::TBitmap> Bitmap(new Graphics::TBitmap()); try { Bitmap->LoadFromClipboardFormat(CF_BITMAP, cb->GetAsHandle(CF_BITMAP), 0); Canvas->Draw(5, 5, Bitmap.get()); } catch (...) { MessageBeep(0); ShowMessage("Error reading image from clipboard!"); } cb->Clear(); } else { MessageBeep(0); ShowMessage("Cannot find image in clipboard!"); } } void __fastcall TForm1::Button2Click(TObject *Sender) { unsigned int DataHandle; HPALETTE APalette; unsigned short MyFormat; std::auto_ptr<Graphics::TBitmap> Bitmap(new Graphics::TBitmap()); try { Bitmap->LoadFromFile("C:\\Program Files\\Common Files\\CodeGear Shared\\Images\\Splash\\256Color\\FACTORY.BMP"); // generate a clipboard format, with data and palette Bitmap->SaveToClipboardFormat( MyFormat, DataHandle, APalette); // save the data to the clipboard using that format and // the generated data Clipboard()->SetAsHandle(MyFormat,DataHandle); } catch (...) { ShowMessage("Failed to copy image to clipboard!"); } }
Delphi Examples:
{ This example uses a button and an TEdit on a form. When the user clicks the button, any text on the clipboard is pasted into the TEdit. If there is no text on the clipboard, a message box appears. Note: To use this example, you must add Clipbrd to the uses clause. Load the Clipboard by performing a copy in any application. } procedure TForm1.Button1Click(Sender: TObject); begin if Clipboard.HasFormat(CF_TEXT) then begin Edit1.Text := Clipboard.AsText; Clipboard.Clear; end else MessageDlg( 'There is no text on the Clipboard', mtInformation, [mbOK],0); end;
{ The following code draws a bitmap image from the Clipboard when a button is pressed. The SaveToClipboard button must be selected before the LoadFromClipboard button in order to place the icon on the clipboard. } procedure TForm1.Button1Click(Sender: TObject); var Bitmap : TBitmap; s : string; Icon: TIcon; begin Bitmap := TBitMap.Create; try Image1.Picture.RegisterClipboardFormat(cf_BitMap,TIcon); Bitmap.LoadFromClipBoardFormat( cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0); Canvas.draw(0,0,Bitmap); finally Bitmap.free; Clipboard.Clear; end; end; procedure TForm1.Button2Click(Sender: TObject); var MyFormat : Word; Bitmap : TBitMap; AData : THandle; APalette : HPALETTE; begin Bitmap := TBitmap.Create; try Bitmap.LoadFromFile('c:\Program Files\Common Files\CodeGear Shared\Images\Splash\256color\factory.bmp'); Bitmap.SaveToClipBoardFormat( MyFormat, AData, APalette); ClipBoard.SetAsHandle(MyFormat,AData); finally Bitmap.Free; end; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|