Copies an AnsiString (long string) to a null-terminated string.
function StrPCopy(Dest: PAnsiChar; const Source: AnsiString): PAnsiChar; overload; function StrPCopy(Dest: PWideChar; const Source: UnicodeString): PWideChar; overload;
PAnsiChar StrPCopy(PAnsiChar Dest, const AnsiString Source); PWideChar StrPCopy(PWideChar Dest, const UnicodeString Source);
StrPCopy copies Source into a null-terminated string Dest. It returns a pointer to Dest.
StrPCopy does not perform any length checking.
The destination buffer must have room for at least Length(Source)+1 characters.
C++ Examples:
/* The following example uses an edit control, a label, and a button on a form. When the button is clicked, the label’s caption and the edit control’s text are combined in a buffer. Then the buffer is displayed in the label’s caption. */ #include <memory> //for STL auto_ptr class void __fastcall TForm1::Button1Click(TObject *Sender) { std::auto_ptr<char> szBuffer(new char[Label1->Caption.Length() + Edit1->Text.Length() + 1]); StrPCopy(szBuffer.get(), Label1->Caption); StrCat(szBuffer.get(), Edit1->Text.t_str()); Label1->Caption = szBuffer.get(); Edit1->Clear(); }
Delphi Examples:
{ This example requires a button on a form and uses StrPCopy to copy a string into an array and then display the character array on the form canvas. StrPCopy does not do length checking. } procedure TForm1.Button1Click(Sender: TObject); var A: array[0..79] of Char; S: String; begin S := 'Honk if you know Blaise.'; StrPCopy(A, S); Canvas.TextOut(10, 10, string(A)); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|