ReplaceText (C++)
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
- Vcl.Dialogs.TReplaceDialog.OnReplace ( fr | de | ja )
- Vcl.Dialogs.TReplaceDialog.ReplaceText ( fr | de | ja )