StrCat (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

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. StrCat and StrCopy only work on narrow width characters.

Code

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  wchar_t* szBuffer = new wchar_t[Label1->Caption.Length() + Edit1->Text.Length() + 1];

  // The following two lines are used in VCL applications.
  StrCopy(szBuffer, Label1->Caption.c_str());
  StrCat(szBuffer, Edit1->Text.c_str());
  Label1->Caption = szBuffer;
  Edit1->Clear();
  delete [] szBuffer;
}

Uses