RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TClipboard.AsText Property

Represents the contents of the clipboard as a string.

Pascal
property AsText: string;
C++
__property AnsiString AsText;

Use the AsText property to place text in and retrieve text from the clipboard. The clipboard must contain a string or an exception occurs. To determine if the clipboard contains a string, pass CF_TEXT to the HasFormat method.  

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);
}

 

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;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!