RAD Studio VCL Reference
SysUtils.StrECopy Function

Copies null-terminated string.

function StrECopy(Dest: PAnsiChar; const Source: PAnsiChar): PAnsiChar; overload;
function StrECopy(Dest: PWideChar; const Source: PWideChar): PWideChar; overload;
PAnsiChar StrECopy(PAnsiChar Dest, const PAnsiChar Source);
PWideChar StrECopy(PWideChar Dest, const PWideChar Source);

StrECopy copies Source to Dest and returns StrEnd(Dest). 

StrECopy does not perform any length checking. The destination buffer must have room for at least StrLen(Source)+1 characters. 

Nested calls to StrECopy to concatenate a sequence of strings run more efficiently than multiple calls to StrCat.  

C++ Examples: 


The following example uses an edit control, a label, and a
button on a form. When the button is clicked, the edit
control’s text is appended to a static buffer. Then the
buffer is displayed in the label’s caption.
const static int MAX_LENGTH = 15;
void __fastcall TForm1::Button1Click(TObject *Sender)
  static char szBuffer[MAX_LENGTH];
  static char* pszBuffer = szBuffer;

  if (StrLen(pszBuffer) + StrLen(Edit1->Text.c_str()) < MAX_LENGTH)
    pszBuffer = StrECopy(pszBuffer, Edit1->Text.t_str());
    ShowMessage("Can't fit new string in allocated memory space.");
  Label1->Caption = szBuffer;


Delphi Examples: 

This example uses a button on a form.  Since StrECopy returns
the destination char array, nested calls are possible and
actually more efficient than repeated calls.  StrECopy does
no bounds checking. When the button is clicked, the inline
text is appended to a static buffer. Then the buffer is
displayed in the form's canvas.

procedure TForm1.Button1Click(Sender: TObject);
  Turbo: PChar = 'Object';
  Pascal: PChar = 'Pascal';
  S: array[0..15] of Char;
  SysUtils.StrECopy(SysUtils.StrECopy(SysUtils.StrECopy(S, Turbo), ' '), Pascal);
  Canvas.TextOut(10, 10, string(S));


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