[Solved]How to invoke help for TToolButton and TAction lazarus / 31-LCL ---------------------------------------------------------------------- glorfin · 2019-01-22 21:45 Hi all! TToolButton and TAction components have HelpContext, HelpKeyWord and HelpType properties. Apparently, it is supposed that a user can invoke help for these components by pressing F1. But when and how? These components cannot be focused. Even if a ToolButton is pressed with a mouse and F1 is pressed simultaneously, help is invoked for previously focused component. ---------------------------------------------------------------------- lucamar · 2019-01-22 22:40 I don't know about TTolButton but TAction's properties, including help related ones, are aplied  to the control it's assigned to, p.e. a TMenuItem. IIRC, actions alone, by themselves, only respond to their shorcut. ---------------------------------------------------------------------- glorfin · 2019-01-22 22:47 Quote from: lucamar on January 22, 2019, 11:40:03 pmI don't know about TTolButton but TAction's properties, including help related ones, are aplied  to the control it's assigned to, p.e. a TMenuItem. IIRC, actions alone, by themselves, only respond to their shorcut. And if an Action is applied to TToolButton - question remains... ---------------------------------------------------------------------- wp · 2019-01-22 22:59 I think this is not directly possible for a TToolButton (or TSpeedButton, or other TGraphicControl descendants). But I could imagine a special "InvokeHelpButton" which, if Checked, switches the toolbutton to a state in which they invoke the help file instead of executing the regular OnClick code. Such a scenario - which does require some programming, of course - does need the help context information. ---------------------------------------------------------------------- lucamar · 2019-01-22 23:17 Quote from: wp on January 22, 2019, 11:59:54 pmBut I could imagine a special "InvokeHelpButton" which, if Checked, switches the toolbutton to a state in which they invoke the help file instead of executing the regular OnClick code. Or a popup menu with a "help" item; much less hasle! The only way you can get help directly for a control by simply presing F1 is when the control has the focus; and since TGraphicControl descendants (in general) can not have the focus ... You get the drift, don't you? ---------------------------------------------------------------------- glorfin · 2019-01-22 23:33 Quote from: lucamar on January 23, 2019, 12:17:10 am The only way you can get help directly for a control by simply presing F1 is when the control has the focus; and since TGraphicControl descendants (in general) can not have the focus ... You get the drift, don't you? Yes, this is exactly the problem. Solution with popup menu overloads UI. Probably, special button could be better. I remember, in some old programs there was button which made mouse cursor to "?" and click on an element invoked help for it. Maybe I'll try to do something like this. ---------------------------------------------------------------------- glorfin · 2019-01-22 23:36 So, gentlemen, thank you for the comments and suggestions. When I have working code, I'll show here the snippets. ---------------------------------------------------------------------- jamie · 2019-01-23 00:16 The TabStop property has been detoured in the class to not allow it to be set to TRUE.. I think this is the code I looked at before and this was done to not allow the Toolbar to gain focus which is what you need.  The ToolBar control needs a little work so that it can handle the Keyboard input to capture the F1 key which then could call the selected ToolButton or where ever the cursor is hanging over to generate the correct info.  Toolbar does have the keyboard events in it since it is a TwinControl.  Maybe the boys could undo the stabbing they did to the TabStop..  There are other ways around this ofcourse, you could put a Tbutton nearby for a Help and have that focused so that all key input goes there. within that control one could test where the mouse is hanging over and determine which help context to call.  Something Like a TPanel first athen place the TToolbar within that and set the tabstop for the panel and handle the F1 hey within the Tpanel ---------------------------------------------------------------------- lucamar · 2019-01-23 00:40 Quote from: jamie on January 23, 2019, 01:16:01 am Toolbar does have the keyboard events in it since it is a TwinControl. [...] There are other ways around this ofcourse, you could put a Tbutton nearby for a Help and have that focused so that all key input goes there. within that control one could test where the mouse is hanging over and determine which help context to call. [... etc ...] You pointed at the solution and then went on with a more problematic one Since the ToolBar itself has keyboard events, it would be easier to just set an OnKeyDown or OnKeyUp handler. It would have to be done in code, since they aren't published but that's not unduly onerous. Yet another solution is to set biHelp in the form's BorderIcons and create a handler for form's OnHelp event but it's less specific. As always: lots of options! ---------------------------------------------------------------------- glorfin · 2019-01-23 00:41 I think I will try help button which sets "help mode" with subsequent use of CursorPos and ControlAtPos to get a button and its context. Once more thank you! Related question: it is impossible to have Help border icon for non- dialog forms, right? ---------------------------------------------------------------------- glorfin · 2019-01-23 00:54 Quote from: lucamar on January 23, 2019, 01:40:46 amYet another solution is to set biHelp in the form's BorderIcons and create a handler for form's OnHelp event but it's less specific. As always: lots of options! It looks like biHelp works only in dialog forms. ---------------------------------------------------------------------- jamie · 2019-01-23 01:04 A toolbar won't receive any key messages because you can't tab to it, you can directly set the focus however,. I just dropped Tpanel and place a Ttoolbar in it. Assigned the OnkeyUp event to a manual event of the panel you can tab to the panel so it becomes focused, I changed the color of the bevel to indicate that with the OnEnter and back to normal with the OnExit In the keyboard event you test for the F1 key and then use the Application.MouseCOntrol  which reports the TtoolButton, from there, you can type cast TToolButton(Application.MouseControl)………. and do what ever you need, force the help system there. ---------------------------------------------------------------------- glorfin · 2019-02-06 23:52 As promiced, my final solution. I defined a variable: ToolButtonHelpContext:integer; Then, in TMainForm.OnAppIdle: ... MPos := ScreenToClient(Mouse.CursorPos);   Control := ControlAtPos(MPos,[capfAllowDisabled,capfRecursive,capfAl lowWinControls]);   if Control is TToolButton then     ToolButtonHelpContext := Control.HelpContext   else     ToolButtonHelpContext := 0; .... In TMainForm, KeyPreview property is set to true, and in TMainForm.FormKeyDown: ... VK_F1: if MainHelpContext <> 0 then           Application.HelpContext(ToolButtonHelpContext);