GetAsHandle (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following code locks the memory corresponding to the text on the Clipboard, then reads the text.

Code

uses clipbrd;

procedure TForm1.Button1Click(Sender: TObject);
var
  MyHandle: THandle;
  TextPtr: PChar;
begin
  ClipBoard.Open;
try
{$IFNDEF UNICODE}
  MyHandle := Clipboard.GetAsHandle(CF_TEXT);
{$ELSE}
  MyHandle := Clipboard.GetAsHandle(CF_UNICODETEXT);
{$ENDIF}

  TextPtr := GlobalLock(MyHandle);
  ListBox1.Items.Add(StrPas(TextPtr));
  GlobalUnlock(MyHandle);
finally
  Clipboard.Close;
end;
end;

Uses