StrComp (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example uses two edit controls and a button on a form. When the button is clicked, the text in the edit controls is compared.


Code

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  wchar_t* szResult = new wchar_t[Edit1->Text.Length() + Edit2->Text.Length() + 20];
  int iResult = StrComp(Edit1->Text.c_str(), Edit2->Text.c_str());
  StrCopy(szResult, Edit1->Text.c_str());
  if (iResult < 0)
	StrCat(szResult, L" is less than ");
  else if (iResult > 0)
	StrCat(szResult, L" is greater than ");
  else
	StrCat(szResult, L" is equal to ");

  StrCat(szResult, Edit2->Text.c_str());
  ShowMessage(String(szResult));
  delete [] szResult;
}

Uses