Recent

Author Topic: Problem adding chm help to an application  (Read 20173 times)

msimeon

  • New Member
  • *
  • Posts: 22
Problem adding chm help to an application
« on: October 03, 2017, 06:44:52 pm »
I am developing a small application as a way to learn Lazarus, under Windows 10.  I want a simple help in the form of a chm help file that gets open by clicking a button or a menu item. I have writen two html files, and produced a chm file using the Microsoft HTML Help Workshop.

The chm viewer triggered by double-clicking the chm file works fine.  When I show the chm file from my application using the lhelp.exe viewer that comes with Lazarus, it does not work properly:
- the links to chapters are ok but the links to sections do not work
- the png images included in the html files do not show up

Any comment or pointer to documents or tutorials or exemples are welcome.

msimeon

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Problem adding chm help to an application
« Reply #1 on: October 03, 2017, 09:50:47 pm »
There are many reports about bugs in lhelp, including this one:
 https://bugs.freepascal.org/view.php?id=14909
Unfortunately it is not perfect.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Problem adding chm help to an application
« Reply #2 on: October 03, 2017, 10:39:11 pm »
If your program will run only on Windows you can also apply the chm viewer of Windows:
  • "use" unit htmlhelp in the main form of the project (htmlhelp is found in fpc/.../packages/winunits-base/src)
  • in OnCreate of the main form add this:
Code: Pascal  [Select][+][-]
  1. var
  2.   chmfile: String;
  3. ...
  4.   chmfile := ChangeFileExt(Application.ExeName, '.chm');
  5.   if FileExists(chmfile) then begin
  6.     Application.HelpFile := chmfile;
  7.     Application.OnHelp := HelpHandler;
  8.   end;
  • Write a handler for the OnHelp event:
Code: Pascal  [Select][+][-]
  1. function TMainForm.HelpHandler(Command:word; Data:Longint; var CallHelp:Boolean): Boolean;
  2. // Call online-help
  3. begin
  4.   // Call HTML help (.chm file)
  5.   htmlHelp.HtmlHelp(0, //Handle, // Application.Handle
  6.     PChar(Application.HelpFile),
  7.     HH_HELP_CONTEXT,
  8.     Data);
  9.   // Don't call regular help
  10.   CallHelp := False;
  11. end;
  • Assign the help context number defined in the chm file to each control for which you want to call help by pressing F1.
I just re-checked this with an old project, it works.

msimeon

  • New Member
  • *
  • Posts: 22
Re: Problem adding chm help to an application
« Reply #3 on: October 03, 2017, 10:57:07 pm »
Thanks for the quick feed back. I'll try it out and let you know.
MS

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Problem adding chm help to an application
« Reply #4 on: October 04, 2017, 02:06:10 pm »
Do note that chm help is not available (by default) on all windows versions out there. MS tries to discourage its usage, e.g. would require a separate download/installation. chm is labeled unsafe (and it actually is).

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Problem adding chm help to an application
« Reply #5 on: October 04, 2017, 02:38:35 pm »
Do note that chm help is not available (by default) on all windows versions out there. MS tries to discourage its usage, e.g. would require a separate download/installation. chm is labeled unsafe (and it actually is).

Which ones don't support CHM?  Are you sure you are not confusing with .hlp, or are you refering to embedded or devicespecific versions (like the original surface?)

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Problem adding chm help to an application
« Reply #6 on: October 04, 2017, 03:01:41 pm »
@marcov:
Indeed i might have confused some things with the .hlp format. However, there is more to it.

Some versions of windows did not came with internet explorer, afaik it is a requirement for proper html help support. Also afaik, starting from win7, there are some slight incompatibilities (e.g. features torn out for security reasons). Nothing that can't be fixed with a download though.

Embedded windows version might have more issues then html alone, but that is a pretty specific platform that would probably not be relevant enough to justify my remark.

I made the comment so that TS is able to take into consideration that his help file might not be shown without issues on each and every machine when falling back to windows html help viewer. Perhaps not relevant for some homebrew usage but might perhaps be if there is a larger user-base.

Please feel free to correct as i was indeed mixing things with .hlp format.

PS: when in doubt there is always msdn to the rescue  :)
« Last Edit: October 04, 2017, 03:17:51 pm by molly »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Problem adding chm help to an application
« Reply #7 on: October 04, 2017, 04:15:21 pm »
@marcov:
Indeed i might have confused some things with the .hlp format. However, there is more to it.

Some versions of windows did not came with internet explorer, afaik it is a requirement for proper html help support. Also afaik, starting from win7, there are some slight incompatibilities (e.g. features torn out for security reasons). Nothing that can't be fixed with a download though.

Actually that is mostly  XPsp2 that does that. With MSIE under attack, some features that were impossible to support (like running activeX binaries inside help) were disabled. Some more minor features were added in the versions after that. But those were not exactly straightforward usage, and lhelp.exe doesn't even have a chance of supporting that, so I don't really understand why it is relevant.

Afaik CHM is still the recommended help system (if you can actually find a place that recommends a helpsystem, since making normal apps is considered something of a bygone era). Even on stackoverflow people programming in C# are still asking CHM related questions.

Quote
Embedded windows version might have more issues then html alone, but that is a pretty specific platform that would probably not be relevant enough to justify my remark.

Quote
I made the comment so that TS is able to take into consideration that his help file might not be shown without issues on each and every machine when falling back to windows html help viewer. Perhaps not relevant for some homebrew usage but might perhaps be if there is a larger user-base.

Afaik all those features don't work with lhelp anyway, and it is a lot more stable. The old MSIE, crippled in quirk modes as it is, still is a full scale browser and magnitudes more versatile than the ipro htmlview widget of lhelp.

Quote
Please feel free to correct as i was indeed mixing things with .hlp format.

I think you should rephrase with concrete issues. You seem to be discouraging windows native CHM in very broad statements, but it is not clear if the alternative (lhelp) supports it at all

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Problem adding chm help to an application
« Reply #8 on: October 04, 2017, 05:29:49 pm »
Actually that is mostly  XPsp2 that does that. With MSIE under attack, some features that were impossible to support (like running activeX binaries inside help) were disabled. Some more minor features were added in the versions after that. But those were not exactly straightforward usage,
I stand corrected. Thank you.

Quote
and lhelp.exe doesn't even have a chance of supporting that, so I don't really understand why it is relevant.
Because html workshop allows you to. But you are corrrect: TS did indicate wanting to use a _simple_ help file only.

Quote
Afaik CHM is still the recommended help system (if you can actually find a place that recommends a helpsystem, since making normal apps is considered something of a bygone era). Even on stackoverflow people programming in C# are still asking CHM related questions.
afaik CHM is indeed the recommended help system for windows platforms. The remark you made there was part of the reason for us to phase out support for Windows, and for me personally to drop it all together ages ago.

Quote
Afaik all those features don't work with lhelp anyway, and it is a lot more stable. The old MSIE, crippled in quirk modes as it is, still is a full scale browser and magnitudes more versatile than the ipro htmlview widget of lhelp.
See my first remark. I don't fully understand the type of comparison you made between lhelp and native html help.

Quote
I think you should rephrase with concrete issues. You seem to be discouraging windows native CHM in very broad statements, but it is not clear if the alternative (lhelp) supports it at all
I am not discouraging CHM help in any way. If you've read that in my words then either i did a very lousy job (most likely) or you read more into my words then there is.

The only argument i would have against html help is that it isn't cross-platform friendly.

If your argument is that every (relevant) windows out there supports the solution as shown by wp, so that TS is able to view his help file that way, then that would be an argument i wouldn't dare to make myself. My experience is otherwise, but is based on recollection of experience from the past. I do not have the resources  (anymore) to check each and every release/update of windows to support my argument (nor do i want to).

msimeon

  • New Member
  • *
  • Posts: 22
Re: Problem adding chm help to an application
« Reply #9 on: October 05, 2017, 12:12:42 pm »
@wp

I tried your code, but it would not compile, the line "    Application.OnHelp := HelpHandler;" in the FormCreate procedure produces an error (wrong number of parameters).

Did I miss something ?  My small test file is attached

Thanks again

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Problem adding chm help to an application
« Reply #10 on: October 05, 2017, 12:52:26 pm »
Do you use 64-bit? The earlier signature is compatible with 32-bit.

Adjust the second parameter to ptrint.


Code: Pascal  [Select][+][-]
  1. type THelpEvent = function(Command: Word; Data: PtrInt; var CallHelp: Boolean): Boolean of object;

msimeon

  • New Member
  • *
  • Posts: 22
Re: Problem adding chm help to an application
« Reply #11 on: October 05, 2017, 01:42:32 pm »
@Marcov

Thank you,
Yes, I use 64-bits and I have done as you say, but it does not solve the basic problem, the code proposed by wp does not compile !

balazsszekely

  • Guest
Re: Problem adding chm help to an application
« Reply #12 on: October 05, 2017, 02:02:39 pm »
You need:
Code: Pascal  [Select][+][-]
  1. Application.OnHelp := @HelpHandler;
instead of
Code: Pascal  [Select][+][-]
  1. Application.OnHelp := HelpHandler;
or switch to mode delphi.

msimeon

  • New Member
  • *
  • Posts: 22
Re: Problem adding chm help to an application
« Reply #13 on: October 05, 2017, 03:42:14 pm »
@GetMem

Thanks for your help.

One more step, but not the last one.  Now my small test project (zip attached) does compile, but it does not run !!!

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Problem adding chm help to an application
« Reply #14 on: October 05, 2017, 04:01:07 pm »
If you post code (which is always good) you should add all files needed for us to compile and run the program, i.e. pas, lfm, lpi and lpr files, and in your case, also the chm file. No compiler-generated files please (.ppu, .exe, .o, etc).

 

TinyPortal © 2005-2018