procedure TForm1.btnFindClick(Sender: TObject);
begin
FindDialog1.Execute;
end;
...
procedure TForm1.btnReplaceClick(Sender: TObject);
begin
ReplaceDialog1.Execute;
end;
procedure TForm1.ReplaceDialog1Replace
(Sender: TObject);
var
SelPos, SPos, SLen, TextLength: Integer;
SearchString : string;
begin
with TReplaceDialog(Sender) do begin
TextLength:=Length(Memo1.Lines.Text);
SPos:=Memo1.SelStart;
SLen:=Memo1.SelLength;
SearchString := Copy(Memo1.Lines.Text,
SPos + SLen + 1,
TextLength - SLen + 1);
SelPos := Pos(FindText, SearchString);
if SelPos > 0 then begin
Memo1.SelStart := (SelPos - 1) + (SPos + SLen);
Memo1.SelLength := Length(FindText);
{remove this in the OnFind procedure:}
Memo1.SelText := ReplaceText;
end
else MessageDlg('Could not find "' + FindText +
'" in Memo1.', mtError, [mbOk], 0);
end;
end;