RAD Studio VCL Reference
|
Contains the text that should replace FindText.
property ReplaceText;
__property ReplaceText;
FindText, taken from the Find What edit box, contains the text string that the user wants to search for. ReplaceText, taken from the Replace With edit box, contains the text string that will replace FindText. To make a default text string appear in the Replace With edit box when the dialog opens, assign a value to ReplaceText in the Object Inspector or in program code.
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); }
/* The following code calls the user-defined routine DoReplace if the Replace button was clicked, or calls the user-defined routine DoReplaceAll if the Replace All button was clicked. Place a TReplaceDialog, a TButton and a TRichEdit in the form. */ void __fastcall TForm1::ReplaceDialog1Replace(TObject *Sender) { TReplaceDialog *dlg = dynamic_cast<TReplaceDialog *>(Sender); if (dlg->Options.Contains(frReplace)) DoReplace(dlg->FindText, dlg->ReplaceText); else if (dlg->Options.Contains(frReplaceAll)) DoReplaceAll(dlg->FindText, dlg->ReplaceText); } void __fastcall TForm1::DoReplace(AnsiString FindText, AnsiString ReplaceText) { ShowMessage( "DoReplace: FindText: " + ReplaceDialog1->FindText + " ReplaceText: " + ReplaceDialog1->ReplaceText); }; void __fastcall TForm1::DoReplaceAll(AnsiString FindText, AnsiString ReplaceText) { ShowMessage( "DoReplaceAll: FindText: " + ReplaceDialog1->FindText + " ReplaceText: " + ReplaceDialog1->ReplaceText); };
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;
{ The following code calls the user-defined routine DoReplace if the Replace button was clicked, or calls the user-defined routine DoReplaceAll if the Replace All button was clicked. Place a TReplaceDialog, a TButton and a TRichEdit in the form. } procedure TForm1.ReplaceDialog1Replace(Sender: TObject); // var FindText, ReplaceText: String; begin with Sender as TReplaceDialog do begin if frReplace in Options then DoReplace(ReplaceDialog1.FindText, ReplaceDialog1.ReplaceText) else if frReplaceAll in Options then DoReplaceAll(ReplaceDialog1.FindText, ReplaceDialog1.ReplaceText); end; end; procedure TForm1.Button1Click(Sender: TObject); begin ReplaceDialog1.Execute; end; procedure TForm1.DoReplace(FindText, ReplaceText: String); begin ShowMessage( 'DoReplace: FindText: ' + ReplaceDialog1.FindText + ' ReplaceText: ' + ReplaceDialog1.ReplaceText); end; procedure TForm1.DoReplaceAll(FindText, ReplaceText: String); begin ShowMessage( 'DoReplaceAll: FindText: ' + ReplaceDialog1.FindText + ' ReplaceText: ' + ReplaceDialog1.ReplaceText); end; procedure TForm1.FormCreate(Sender: TObject); const Path = 'OverView.RTF'; begin RichEdit1.PlainText := False; RichEdit1.Lines.LoadFromFile(Path); RichEdit1.ScrollBars := ssVertical; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|