RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TClipboard.Open Method

Opens the clipboard, preventing other applications from changing its contents until the clipboard is closed.

Pascal
procedure Open; virtual;
C++
virtual __fastcall Open();

Call Open before adding a series of items to the clipboard. This prevents other applications from overwriting the clipboard until it is closed. (When adding a single item to the clipboard, there is no need to call Open.) 

When an application has finished adding items to the clipboard, it should call the Close method. The clipboard can be opened with multiple calls to the Open method before being closed. Open and Close maintain a count of the number of times the clipboard has been opened and will not close it until Close has been called the same number of times.  

C++ Examples: 

 

/*
The following code locks the memory for text on the Clipboard, then
reads the text.
*/
#include <Clipbrd.hpp>

void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString MyString;

int TextHandle;
PChar pText;

Clipboard()->Open();
try
{
  TextHandle = Clipboard()->GetAsHandle(CF_UNICODETEXT);
  pText = (PChar)GlobalLock((HGLOBAL)TextHandle);
  MyString = pText;
  ListBox1->Items->Add(StrPas(pText));
  GlobalUnlock((HGLOBAL)TextHandle);
}
catch (...)
{
  Clipboard()->Close();
  throw;
}
Clipboard()->Close();
}

 

Delphi Examples: 

{
The following code locks the memory for text on the Clipboard, then reads the text.
}

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;

 

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