I have been trying to detect when the user is trying to open the help for something. Switching a form to "KeyPreview:= True" and catching the "OnKeyDown" event works, but does not cut it. Plus, this project has hundreds of forms, and I'm not going to go do this on each and every form, and try to remember later to add it to any new forms, etc.
Therefore, I have been seeking a global application-level event handler for catching the help. In the "Application" object, there is in fact an event "OnHelp" which I tried to use, but for some reason this event is never triggered. The goal is to provide 2 help resources for the application: A) regular HTML help (.chm files) which is already there and working, and B) online help to open a corresponding webpage instead of the local help file. In order to do so, I have to catch any possible event of trying to open the help (not just F1), catch the HelpContext ID, cancel the local help file from opening, then open the web page in its place.
Here's my code related to what I'm trying to do...
JD Solutions
Therefore, I have been seeking a global application-level event handler for catching the help. In the "Application" object, there is in fact an event "OnHelp" which I tried to use, but for some reason this event is never triggered. The goal is to provide 2 help resources for the application: A) regular HTML help (.chm files) which is already there and working, and B) online help to open a corresponding webpage instead of the local help file. In order to do so, I have to catch any possible event of trying to open the help (not just F1), catch the HelpContext ID, cancel the local help file from opening, then open the web page in its place.
Here's my code related to what I'm trying to do...
Code:
function TForm1.AppHelp(Command: Word; Data: Longint; var CallHelp: Boolean): Boolean;
begin
//Breakpoint here is never reached
if WebHelp then begin //Check if user's option to use Web Help is enabled
CallHelp:= False; //Cancel local help from opening
DoHelp(Data); //Open web help instead
//is "Data" supposed to be the HelpContext ID?
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnHelp:= AppHelp; //assigning function to event
end;
procedure TForm1.DoHelp(const HelpContext: Integer);
const
WebRoot = '[URL unfurl="true"]http://mycompanywebsiteroot.com/Help.htm?id=';[/URL]
begin
//Help.htm is a page that redirects to proper page based on 'id' parameter
ShellExecute(WindowHandle, 'open', PChar(WebRoot+IntToStr(HelpContext)), nil, nil, SW_SHOWNORMAL); //launch web page in default browser
end;
JD Solutions