1
votes

I am using Delphi XE7 and my question pertains to when accelerator keys (aka Access Keys) should be displayed. Specifically, I have noticed that if I display a secondary form (ie, not the main form) and press the Alt key, the accelerators are displayed (the expected behavior). If I then close and re-open the dialog, the accelerators are still displayed (without pressing Alt). Is that considered correct Windows 7 behavior? If this is not correct behavior, then what code (if any) could I add to the form's OnShow that would rehide the accelerators?

1

1 Answers

2
votes

The platform standard is that access keys are shown if the dialog was invoked by a keyboard action. Once the dialog is shown, if you press the ALT key then the access keys are shown.

So, why are the access keys shown when you open the form for a second time? Well, if you are creating the form each time you show it, then you will get the platform standard behaviour outlined above. So I conclude that in between first and second showing of the form you are merely hiding it, rather than destroying it.

So, the simple way to get the behaviour that you desire is to destroy the form when it is closed, and create it when it shown. Don't use the global form variable that the IDE creates for you. Don't call Application.CreateForm in the .dpr file to create that global instance. Whenever you need to show the form, create it at that instance. When the form is closed, destroy that instance.

If you have to re-show an existing instance of a form, then send a WM_CHANGEUISTATE message to initialize the state. Pass UIS_INITIALIZE or (UISF_HIDEACCEL shl 16) as wParam. If can't test any of this but it will be along these lines. I think it's enough to send this to just the form's window handle. And I might have got the flags wrong. Documentation here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646342(v=vs.85).aspx