RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.StrCat Function

Appends a copy of Source to the end of Dest and returns the concatenated string.

Pascal
function StrCat(Dest: PAnsiChar; const Source: PAnsiChar): PAnsiChar; overload;
function StrCat(Dest: PWideChar; const Source: PWideChar): PWideChar; overload;
C++
PAnsiChar StrCat(PAnsiChar Dest, const PAnsiChar Source);
PWideChar StrCat(PWideChar Dest, const PWideChar Source);

Use StrCat to concatenate Source to the end of Dest. StrCat does not perform any length checking. The destination buffer must have room for at least StrLen(Dest)+StrLen(Source)+1 characters. 

To check length, use the StrLCat function.  

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]);
  // The following 2 lines are used in VCL applications
  StrCopy(szBuffer.get(), AnsiString(Label1->Caption).c_str());
  StrCat(szBuffer.get(), AnsiString(Edit1->Text).c_str());
  Label1->Caption = szBuffer.get();
  Edit1->Clear();
}

 

Delphi 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.
} 
procedure TForm1.Button1Click(Sender: TObject);
var
  Buffer: PChar;
begin
  GetMem(Buffer,Length(Label1.Caption) + Length(Edit1.Text) + 1);
  StrCopy(Buffer, PChar(Label1.Caption));
  SysUtils.StrCat(Buffer, PChar(Edit1.Text));
  Label1.Caption := Buffer;
  Edit1.Clear;
  FreeMem(Buffer);
end;

 

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