RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TReplaceDialog.ReplaceText Property

Contains the text that should replace FindText.

Pascal
property ReplaceText;
C++
__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 = (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) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!