Thursday, June 25, 2009

MessageDlg and ShortCuts

Today I came across an interesting problem:
A user of the tube inspection system I develop reported that he was not able to emergency stop the automatic probe drive under certain circumstances. The hardware emergency stop button worked of course but the usual way of using a short cut in the software did not. The emergency stop short cut is implemented using the Application.OnShortCut event which should be fired under all circumstances but apparently it does not. We drilled the problem down to fact that Key events do not arrive in the application message loop when a modal message box (created using the Dialogs.MessageDlg function) is shown.
Fortunately the Dialogs unit also provides the function

function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; DefaultButton: TMsgDlgBtn): TForm; overload;

which allows to create a very similar dialog and which when opened modally still allows to handle short cuts.
PS:
During my search for a solution to my problem I came across a very interesting by Peter Below: A Key's Odyssey.