RAD Studio VCL Reference
|
property OnReplace;
__property OnReplace;
OnReplace occurs whenever the user clicks Replace or Replace All. In addition, when the user clicks Replace, the frReplace flag is set (and the frReplaceAll flag is turned off) in Options. When the user clicks ReplaceAll, the frReplaceAll flag is set (and the frReplace flag is turned off) in Options.
Write an OnReplace event handler that searches for the text specified in FindText and replaces it with the text in ReplaceText. Use the Options flags to determine how the search is conducted.
C++ Examples:
/* The following event handler searches a TMemo object called Memo1 and replaces FindText with ReplaceText. It uses TMemo’s SelStart, SelLength, and SelText properties. */ 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 selected text with ReplaceText Memo1->SelText = dlg->ReplaceText; } else MessageBeep(0); }
Delphi Examples:
{ The following event handler searches a TMemo object called Memo1 and replaces FindText with ReplaceText. It uses TMemo’s SelStart, SelLength, and SelText properties. } procedure TForm1.ReplaceDialog1Replace(Sender: TObject); var SelPos: Integer; begin with TReplaceDialog(Sender) do begin { Perform a global case-sensitive search for FindText in Memo1 } SelPos := Pos(FindText, Memo1.Lines.Text); if SelPos > 0 then begin Memo1.SelStart := SelPos - 1; Memo1.SelLength := Length(FindText); { Replace selected text with ReplaceText } Memo1.SelText := ReplaceText; end else MessageDlg(Concat('Could not find "', FindText, '" in Memo1.'), mtError, [mbOk], 0); end; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|