Re: Copying a String var to Clipboard ?

Posted by Lennie De Villiers on May 12, 2003 at 12:45:57:

In Reply to: Copying a String var to Clipboard ? posted by Lennie De VIlliers on May 12, 2003 at 12:02:37:

Hello Guys!

I found the solution:

uses
  Clipbrd;
...
  Clipboard.AsText := StrVar;   // Where StrVar is the name of var you want in clipboard

Copy From Delphi Online Help:

Represents the content of the clipboard as a string.

property AsText: string;

Description

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.

Example:

This example uses a button and an edit control on a form. When the user clicks the button, any text on the clipboard is pasted into the edit control. 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.

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Clipboard.HasFormat(CF_TEXT) then
    Edit1.Text := Clipboard.AsText
  else
    MessageDlg('There is no text on the Clipboard', mtInformation, [mbOK], 0);
end;

Lennie De Villiers