Problem with AdvMemo1.FindAndReplace

Hello,

FindAndReplace did't work correcly, I think. Here is a litte Minimal-Demo:

AdvMemo.zip (6.9 KB)

After program start, type somthing like
Edit1 Edit2 Edit3
Edit1 Edit2 Edit1
Then press Save. Now you can press SearchAndReplace-Button.
Edit2 Edit2 Edit3
Edit2 Edit2 Edit2
So far as expected. All ist fine.
Then press Load. You'll get back the original text:
Edit1 Edit2 Edit3
Edit1 Edit2 Edit1
Then press SearchAndReplace-Button again, and nothing happens :frowning:
You can also restart the App. After pressing Load & SearchAndReplace, nothing happens.

Thanks and Best Regards
Martin Specht

Change your code to:

begin
  AdvMemo1.FindAndReplace(Edit1.Text,Edit2.Text,[frReplaceAll,frDown])
end;

Ok, changed the code. And the first SearchAndReplace-Button-Call works as expected.
I'll get this:
Edit2 Edit2 Edit3
Edit2 Edit2 Edit2
Changing this manually to
Edit2 Edit1 Edit3
Edit2 Edit1 Edit2
And pressing the S&R-Button again, I'll get
Edit2 Edit1 Edit3
Edit2 Edit1 Edit2
Press it again, I'll get:
Edit2 Edit1 Edit3
Edit2 Edit2 Edit2
I am a little bit confused :frowning:
Pressing S&R again, nothing happens.

Thanks and Best Regards
Martin

Search & replace always starts from the selection.
If you want to perform the replacement on the entire memo, change your code to:

> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   AdvMemo1.GotoBegin;
>   AdvMemo1.FindAndReplace(Edit1.Text,Edit2.Text,[frReplaceAll,frDown])
> end;

Ok, I understand. That means the cursor position is relevant for the find and replace area.
Thanks and best regards
Martin

Find starts from cursor position.