Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnChange() has wrong Modification flag if user presses Ctrl+Z #246

Open
danielmarschall opened this issue Nov 3, 2023 · 2 comments
Open

Comments

@danielmarschall
Copy link

danielmarschall commented Nov 3, 2023

Example code:

procedure TForm1.SynEdit1Change(Sender: TObject);
var
  tmp: string;
begin
  tmp := StringReplace(Caption, '*', '', [rfReplaceAll]);
  if SynEdit1.Modified then tmp := tmp + '*';
  if Caption <> tmp then Caption := tmp;
end;

If the user enters something, then a asterisk will be added to the Caption.

If the change is reverted using Ctrl+Z , the asterisk should disappear again, but this does not work because SynEdit1.Modified is true inside the OnChange Event. Modified should be false not true in this case.

However, after the OnChange Event, the Modified flag is set correctly.

So the "dumb" workaround for the issue is checking it with a timer.

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  SynEdit1Change(SynEdit1);
end;
@danielmarschall
Copy link
Author

(Addendum: If you fix it, please also verify that the Modification will be true if the user reverts the revert by pressing Ctrl+Y. This might be another case to be considered)

@pyscripter
Copy link
Contributor

Use the OnStatusChange event for this purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants