//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "GetAsHandle.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: GetAsHandle
// Method: Clipbrd.TClipboard.GetAsHandle
// Method: Clipbrd.TClipboard.Open
// Method: Clipbrd.TClipboard.Close
// Routine: SysUtils.StrPas

// BeginCode
/*
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();
}
// EndCode
// EndExample: GetAsHandle
//---------------------------------------------------------------------------
