Using Delphi XE2 and also Delphi 6
I discovered that hitting F1 to open the help file to a help context does not open the help file to the proper context yet using the menu item for which F1 is the shortcut, opens the help file to the proper context. I also have a button that calls the menu item code.
I checked to make sure both F1 and the menu item and the button are calling the exact same line of code and they are:
procedure TForm1.Help1Click(Sender: TObject);
begin
Application.HelpContext(Self.HelpContext);
end;
Self.HelpContext
value is changed depending on where the user is in the form and I verified that when that line is executed Self.HelpContext
is the correct value and is the same value when called via F1 or the menu item or the button.
I verified this issue also exists in every previous version of our app written in Delphi 6.
There must be something simple I'm missing here. Any ideas?
What is happening is that F1 gets special treatment by the system. Yes it is true that your menu item's handler that has a shortcut of F1 fires. But after that handler has fired, the app receives a WM_HELP
message.
This WM_HELP
message is processed initially by TCustomForm.WMHelp
. This looks up the help context ID associated with the active control. And then Application.HelpContext
is called using that help context. And presumably the active control's help context ID differs from that of the form.
So, although your menu item opens the help file at your preferred topic, the subsequent WM_HELP
overrides the menu item.
It appears that you want all F1 always to route to the form's help context ID. In which case, my advice would be as follows:
HelpContext
for the form.HelpContext
properties for all other controls on your form. In other words, revert them to the default value of 0
.Then when the WM_HELP
message is handled, it starts at the active control and find a help context of 0
. Then it will rise up through the parents to the form, which is non-zero.
I think that I would also remove the F1 shortcut from the menu item / action. And let the WM_HELP
message be the mechanism for invoking help.