You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug in SearchReplace procedure, returning wrong result upon Cancel . . . with fix
In the "SearchReplace" function, in SynEdit.pas
There should be a "Dec(Result)" in response to "raCancel", the same as there is in response to "RaSkip".
Otherwise the function returns the wrong number of replacements.
The following change fixes it:
if bPrompt and Assigned(FOnReplaceText) then
begin
nAction := DoOnReplaceText(ASearch, AReplace, ptCurrent.Line, nFound);
if nAction = raCancel then
begin
Dec(Result); // I added this 12-10-2022
Exit;
end;
end
else . . .
Also, the Search and Replace demo doesn't include a procedure for the ConfirmReplaceDialog.
Here it is:
The "OnReplaceText" event should be set to a procedure like the following:
procedure TForm1.SynEditReplaceText(Sender: TObject; const ASearch,
AReplace: string; Line, Column: Integer; var Action: TSynReplaceAction);
var
res : tmodalresult;
begin
ConfirmReplaceDialog := TConfirmReplaceDialog.Create(self);
try
ConfirmReplaceDialog.lblconfirmation.caption := 'Replace this occurrence of "' + Synedit.SelText + '"?';
ConfirmReplaceDialog.left := self.left + self.width;
ConfirmReplaceDialog.top := self.top + (self.height div 3);
if ConfirmReplaceDialog.left + ConfirmReplaceDialog.width > screen.width then
ConfirmReplaceDialog.left := screen.Width - ConfirmReplaceDialog.width;
res := ConfirmReplaceDialog.ShowModal;
case res of
mrYes : Action := raReplace;
mrNo : Action := raSkip;
mrCancel : Action := raCancel;
mrYesToAll : Action := raReplaceAll;
else Action := raCancel;
end;
finally
ConfirmReplaceDialog.Free;
end;
end;
In the ConfirmReplaceDialog form, mrTryAgain needs to be replaced with mrYesToAll.
The text was updated successfully, but these errors were encountered:
pyscripter
added a commit
to pyscripter/SynEdit
that referenced
this issue
Mar 2, 2024
Bug in SearchReplace procedure, returning wrong result upon Cancel . . . with fix
In the "SearchReplace" function, in SynEdit.pas
There should be a "Dec(Result)" in response to "raCancel", the same as there is in response to "RaSkip".
Otherwise the function returns the wrong number of replacements.
The following change fixes it:
Also, the Search and Replace demo doesn't include a procedure for the ConfirmReplaceDialog.
Here it is:
The "OnReplaceText" event should be set to a procedure like the following:
In the ConfirmReplaceDialog form, mrTryAgain needs to be replaced with mrYesToAll.
The text was updated successfully, but these errors were encountered: