RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.StrPas

Converts null-terminated string to an AnsiString (long string).

This function is provided for backwards compatibility only. To convert a null terminated string to an AnsiString or native Delphi language string, use a typecast or an assignment.  

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!