Context Help in .chm file lazarus / 67-Windows ---------------------------------------------------------------------- Timbo · 2021-09-28 14:39 I'm converting an application developed in Delphi, potentially one of many. It uses context help in a .chm file, with context numbers set in the file and the current context number set within the code. This works correctly with Delphi. I have a CHMHelpDatabase and LHelpConnector on the main form, and have initialised them according to the examples, and everything seems to be working - except that when, for example, the help context is 200, I get a message, presumably from LHelp, saying "Help context 200 not found". As as aside, is there a way I can bypass LHelp and simply invoke the default CHM file viewer? Thanks. ---------------------------------------------------------------------- wp · 2021-09-28 15:23 Quote from: Timbo on September 28, 2021, 04:39:09 pmis there a way I can bypass LHelp and simply invoke the default CHM file viewer? I don't have a simple example for this, but you could look at the application LazStats (https://sourceforge.net/p/lazarus- ccr/svn/HEAD/tree/applications/lazstats/ - download the snapshot if you don't have svn. No external components are required) which I modified to use chm help massively. Look at the MainUnit (in folder "forms"): - Add the unit htmlhelp to "uses"; it comes with FPC (packages/winunits-base) - Add a private method "function HelpHandler(Command: Word; Data: PtrInt; var CallHelp: Boolean): Boolean;" to the main form which does this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // Call HTML help (.chm file)function TOS3MainFrm.HelpHandler(Command: Word; Data: PtrInt;var  s: String;  ws: UnicodeString;  res: Integer;begin  if Command = HELP_CONTEXT then  begin    // see: http://www.helpware.net/download/delphi/hh_doc.txt    ws := UnicodeString(Application.HelpFile);    res := htmlhelp.HtmlHelpW(0, PWideChar(ws), HH_HELP_CONTEXT, Data);  // Data is HelpContext here  end else  if Command = HELP_COMMAND then  begin    s := {%H-}PChar(Data);    // Data is pointer to HelpKeyword here, but the Windows help viewer does    // not want the KeywordPrefix required for LHelp.    if pos(HELP_KEYWORD_PREFIX + '/', s) = 1 then      Delete(s, 1, Length(HELP_KEYWORD_PREFIX) + 1);    ws := UnicodeString(Application.HelpFile + '::/' + s);    res := htmlhelp.HtmlHelpW(0, PWideChar(ws), HH_DISPLAY_TOPIC, 0);  end;   // Don't call regular help  CallHelp := False;   Result := res <> 0;end; - In the main form's OnCreate handler, assign it to the Application.OnHelp event, and set the Application.Helpfile to the name of your chm file: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  helpfn: String;begin  ...  helpfn := Application.Location + 'LazStats.chm';  if FileExists(helpfn) then  begin    Application.HelpFile := helpfn;    Application.OnHelp := @HelpHandler;  end  else    MessageDlg('LazStats help file not found.', mtError, [mbOK], 0);end; This is for Windows only. Study the real code in the application which is extended to use the Lazarus-internal help-database instead which - of course - is cross-platform. ---------------------------------------------------------------------- Timbo · 2021-09-29 10:47 Thanks very much. I had trouble with line 9 in the second snippet of code, getting an error for the @. I fixed it by setting the OnHelp handler for the form using the Object Inspector instead, and now everything is working perfectly. Thanks again! ---------------------------------------------------------------------- marcov · 2021-09-29 10:58 Quote from: Timbo on September 29, 2021, 12:47:54 pmThanks very much. I had trouble with line 9 in the second snippet of code, getting an error for the @. That's a difference between $mode delphi and $mode objfpc probably. In mode delphi just leave it out.