ReplaceText (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following event handler searches for a TMemo object called Memo1 and replaces FindText with ReplaceText. It uses TMemo’s SelStart, SelLength, and SelText properties.

Code

void __fastcall TForm1::ReplaceDialog1Replace(TObject *Sender)
{
  TReplaceDialog *dlg = dynamic_cast<TReplaceDialog *>(Sender);
  /* Perform a global case-sensitive search for FindText in Memo1. */
  int SelPos = Memo1->Lines->Text.Pos(dlg->FindText);
  if (SelPos > 0)
  {
    Memo1->SelStart = SelPos - 1;
	Memo1->SelLength = dlg->FindText.Length();
	// Replace the selected text using ReplaceText.
	Memo1->SelText = dlg->ReplaceText;
  }
  else
	MessageBeep(0);
}

Uses