In my Delphi application I have a custom Yes, No, Cancel dialogue, which will be called from the main form to confirm saving the changes made to the current file edited. This would normally be achieved by messageDlg() but I wanted this dialogue to have customised looks, so I am trying to achieve this functionality by
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 reacts to pressing the Escape key by returning mrNo TModalResult
. And you can see how BAAAD this is, since your intuition tells you that Esc-aping the modal dialogue will CANCEL the intended Quit Application process, but in fact what happens is you issue a Don't save any changes command and application quits.
I have not noticed this behaviour until I lost an hour's work in this fashion. No FormKeyPressed event handler or anything responding to key presses was put into the myModalDialogue code. It just so works that pressing the Esc in forms shown using showModal
will return mrNo
. How can I override this default behaviour?