Modifying the default modal result form.showModal

In my Delphi application, I have a customizable dialog "Yes", "No", "Cancel", which is called from the main form to confirm that changes made to the current edited file are saved. This is usually achieved using messageDlg (), but I wanted this dialog to have a custom look, so I'm trying to achieve this functionality with

case myDialogue.showModal of
  mrYes: <<save changes>>;
  mrNo: <<quit application without saving changes>>
  mrCancel: <<set the closeAction to caNone and do nothing>>
end;

The problem is that by default the form responds to pressing the Escape key, returning mrNo TModalResult. And you can see how BAAAD is, since your intuition tells you that Esc-aping in a modal dialog will CANCEL the proposed Quit Application process, but in fact what you are doing is Do not save any changes The command and the application exit .

I did not notice this behavior until I lost an hour of work in this way. The FormKeyPressed event handler or something in response to keystrokes was not placed in myModalDialogue code. So it works that pressing Esc in the forms shown with showModalwill return mrNo. How can I override this default behavior?

+3
2

, Cancel "" False, Cancel "" - "".

+15

.

+4

Source: https://habr.com/ru/post/1706632/


All Articles