StrECopy (C++)

From Appmethod 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 edit control's text is appended to a static buffer. Then the buffer is displayed in the label's caption.

Code

const static int MAX_LENGTH = 15;

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  static wchar_t szBuffer[MAX_LENGTH];
  static wchar_t* pszBuffer = szBuffer;

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

Uses