Recent

Author Topic: Writing CHM Files.  (Read 4337 times)

Badger

  • Full Member
  • ***
  • Posts: 158
Writing CHM Files.
« on: August 16, 2020, 09:39:32 am »
I'm having problems trying to put help into my project.
  I've tried creating CHM file with HelpNDoc free version and displaying it in lhelp via the command :-
Code: Pascal  [Select][+][-]
  1. If Help.Enabled Then
  2.     ShowHelpOrErrorForKeyword('','PhoenixDatabase/MainPage.html');
  3.  
This displays lhelp perfectly and lhelp seems to function fine.  However, the program displays the error 'lhelp does not respond.' which you see if you close lhelp or do an Alt-Tab.
Is there any obvious reason for this behavior and, as a work around, is there a way to use 'ShowHelp' (What parameters?) so the error message doesn't appear.
I've also tried using Rahman's CHM Maker which works fine except I can't work out how to set up the TOC.  All pages appear as descendants of the main page.
I've also tried the CHM maker in the lazerus Tools directory but this still wouldn't show a TOC. 
These things may be second nature to the wonderful hero members but but to mere mortals it is somewhat more difficult.  As for sub-mortals like myself, there just isn't enough 'Help' with these programs - it isn't that intuitive.  Could someone please explain how to incorporate the TOC in either of these free pascal CHM Makers.

Getting HelpNDoc to work without the error message would be the best because it gives a more 'professional' help file and is easier to use.  However, if not, I would be very grateful to be able to get full use of the other two CHM makers.
Badger
(A bad tempered, grumpy animal that sleeps most of the winter!)

If at first you don't succeed - you're running about average!

I'm using Windows 10 Lazarus v3.6  FPC 3.2.2   Win 32/64

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2032
  • Former Delphi 1-7, 10.2 user
Re: Writing CHM Files.
« Reply #1 on: August 16, 2020, 10:09:12 am »
I use Microsoft's ancient  'HTML Help Workshop' in Win10 (set for compatibility with XP). Never had an issue with displaying the ToC. My help file is only called from the menu thus:

Code: Pascal  [Select][+][-]
  1. procedure TForm1_Main.MenuItem_HelpClick(Sender: TObject);
  2. var
  3.   HelpPath: string;
  4. begin
  5.   {$IFDEF DARWIN}
  6.   HelpPath := GetResourcesPath + 'picinfo.help';
  7.   OpenDocument(HelpPath);
  8.   {$ENDIF}
  9.   {$IFDEF WINDOWS}
  10.   HelpPath :=  GetAppConfigDir(False) + 'picinfo.chm';
  11.   ShellExecute(0, nil, PChar(HelpPath), nil, nil, SW_SHOWNORMAL);
  12.   {$ENDIF}
  13.   {$IFDEF FREEBSD}
  14.   MessageDlg('Help', 'No help for you today :-(', mtInformation, [mbOK],0);
  15.   {$ENDIF}
  16.   {$IFDEF LINUX}
  17.   MessageDlg('Help', 'No help for you today :-(', mtInformation, [mbOK],0);
  18.   {$ENDIF}
  19. end;

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: Writing CHM Files.
« Reply #2 on: August 16, 2020, 11:20:37 am »
The problem with lhelp is that it is rather buggy and ATM there is no dev who really takes care of it. IIRC I think I had that problem, too, and then decided to used the internal help viewer of Windows instead of lhelp. Please have a look at my adaption of LazStats where I rebuilt the help system of the original author, a mixture of html and pdf files, by chm written by means of HelpNDoc. Download the snapshot from https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/applications/lazstats/, no third-party components required. The new system is not yet fully integrated, open one of the Analysis forms and press F1 (The "Help" buttons on the forms call the old help).

These are the steps to invoke MS help:
  • Add htmlhelp to "uses" of the main form.
  • Write this private function of the main form:
Code: Pascal  [Select][+][-]
  1. // Call HTML help (.chm file)
  2. function TOS3MainFrm.HelpHandler(Command: Word; Data: PtrInt;
  3.   var CallHelp: Boolean): Boolean;
  4. var
  5.   topic: UnicodeString;
  6.   res: Integer;
  7.   fn: UnicodeString;
  8. begin
  9.   if Command = HELP_CONTEXT then
  10.   begin
  11.     // see: http://www.helpware.net/download/delphi/hh_doc.txt
  12.     fn := UnicodeString(Application.HelpFile);
  13.     res := htmlhelp.HtmlHelpW(0, PWideChar(fn), HH_HELP_CONTEXT, Data);
  14.   end else
  15.   if Command = HELP_COMMAND then
  16.   begin
  17.     topic := UnicodeString(Application.HelpFile + '::/' + {%H-}PChar(Data));
  18.     res := htmlhelp.HtmlHelpW(0, PWideChar(topic), HH_DISPLAY_TOPIC, 0);
  19.   end;
  20.  
  21.   // Don't call regular help
  22.   CallHelp := False;
  23.  
  24.   Result := res <> 0;
  25. end;
  • In the OnCreate event of the main form, add
Code: Pascal  [Select][+][-]
  1.   Application.HelpFile := Application.Location + 'LazStats.chm';   // use name of your chm file here
  2.   if FileExists(Application.HelpFile) then
  3.     Application.OnHelp := @HelpHandler
  4.   else
  5.     Application.HelpFile := '';
  • Write the chm help file and compile it.
  • For every control for which you want to provide help there should be an item in the chm file. In HelpNDoc this is a separate html file which you can see in the right "inspector-like" grid as "Help-ID". Use this identifier for property "HelpKeyWord" of the control needing help; make sure to add the extension ".htm" (not ".html"!). Alternatively you can also use the numeric HelpContext from HelpNDoc and use is for the equally named property.
  • I think that's all. Compile and run your application. Press F1 on the item for which a chm item exists -> the Windows-builtin help viewer should open with the corresponding text.

Badger

  • Full Member
  • ***
  • Posts: 158
Re: Writing CHM Files.
« Reply #3 on: August 17, 2020, 01:20:34 am »
Many thanks to both of you.

Because I'm simply trying to supply a general help capability through a menu item and want to make the program cross platform, I'll try Trev's solution first. 

I'll leave the topic open till I've tried  things out.
Badger
(A bad tempered, grumpy animal that sleeps most of the winter!)

If at first you don't succeed - you're running about average!

I'm using Windows 10 Lazarus v3.6  FPC 3.2.2   Win 32/64

gour

  • New Member
  • *
  • Posts: 17
Re: Writing CHM Files.
« Reply #4 on: August 17, 2020, 09:07:20 am »
The problem with lhelp is that it is rather buggy and ATM there is no dev who really takes care of it. IIRC I think I had that problem, too, and then decided to used the internal help viewer of Windows instead of lhelp.

I'd also like to  have help file or manual available within my  application and wonder what to do if Linux is my native platform?

Any other format besides *.CHM to create/render manual within Lazarus-powered apps which is multi-platform-friendly?

 

TinyPortal © 2005-2018