Rectangle 27 0

Simulate F1 kepress on active control to load help system Delphi?


procedure TMyForm.ToolButton1Click(Sender: TObject);
begin
  if Assigned(ActiveControl) then begin
    Application.HelpContext(ActiveControl.HelpContext);
  end;
end;

Hi David its fine now this worked, I just had to write some code that goes back up the control's hierarchy. We use DevExpress grids, so the active control in my case was a cell in the grid, I needed to go back up to the parent, i.e. the grid

I tested the code when I wrote the answer. It works. There must be something unusual in your app.

I think you need a tool button OnClick handler that can be as simple as this:

Thanks this works in terms of bringing up the help system. However, the help button is on the toolbar of the main form. When I use this code, the help system is called with the help for the form which is being viewed, even though I have focus in a control that has its own context sensitive help? If I am on the grid and press F1 I get help for the grid

What makes this work is the fact that the controls on a toolbar do not ever become the active control.

Note
Rectangle 27 0

Simulate F1 kepress on active control to load help system Delphi?


Also, don't try to "simulate" a keyboard event. Just call Application.HelpContext directly.

Hi Rob I was trying to figure out why the context number was wrong, but as explained above I have sorted it now thanks for your help

Thanks for this Rob, however, as I just mentioned above I have a problem now where application.contextid appears to be 1 level too high? Instead of being the grid's context id it is the parent form's id?

There are question marks in your comments, but I don't know what question you're asking.

There's something wrong with your toolbar. The system toolbar doesn't ordinarily get the focus it's never the active control. If you're using a real TToolBar and TToolButton, you won't have this problem. Even TSpeedButton won't have this problem. Use the right control for the job.

Note