Lazarus

Using the Lazarus IDE => General => Topic started by: msimeon on October 03, 2017, 06:44:52 pm

Title: Problem adding chm help to an application
Post by: msimeon 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
Title: Re: Problem adding chm help to an application
Post by: JuhaManninen 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.
Title: Re: Problem adding chm help to an application
Post by: wp 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:
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;
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;
I just re-checked this with an old project, it works.
Title: Re: Problem adding chm help to an application
Post by: msimeon on October 03, 2017, 10:57:07 pm
Thanks for the quick feed back. I'll try it out and let you know.
MS
Title: Re: Problem adding chm help to an application
Post by: molly 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).
Title: Re: Problem adding chm help to an application
Post by: marcov 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?)
Title: Re: Problem adding chm help to an application
Post by: molly 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 (https://msdn.microsoft.com/en-us/library/windows/desktop/ms670169(v=vs.85).aspx) to the rescue  :)
Title: Re: Problem adding chm help to an application
Post by: marcov 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
Title: Re: Problem adding chm help to an application
Post by: molly 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).
Title: Re: Problem adding chm help to an application
Post by: msimeon 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
Title: Re: Problem adding chm help to an application
Post by: marcov 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;
Title: Re: Problem adding chm help to an application
Post by: msimeon 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 !
Title: Re: Problem adding chm help to an application
Post by: balazsszekely 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.
Title: Re: Problem adding chm help to an application
Post by: msimeon 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 !!!
Title: Re: Problem adding chm help to an application
Post by: wp 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).
Title: Re: Problem adding chm help to an application
Post by: msimeon on October 05, 2017, 04:23:20 pm
@wp

Here is the full set of files.
Title: Re: Problem adding chm help to an application
Post by: wp on October 06, 2017, 12:57:43 am
1) The project file .lpr is not correct. It is missing the instruction to create the main form.
2) You must assign help context numbers to the controls for which you want to provide context-sensitive help (property HelpContext). These numbers are defined in [MAPS] and [ALIAS] sections of the chm project file (hhp) - this is missing as well.

Find in the attachment a worked-out example containing all files needed for the chm project; the project is created by means of the batch file "compile.bat" (you may have to adapt the path to the Microsoft HTML Help Compiler). There is also a complete Lazarus project from which this help file can be called from three buttons as context-sensitive help (press F1), or from a help menu.

This is an instruction how to create a chm help project for the Microsoft HTML Help Workshop: http://www.libertybasicuniversity.com/lbnews/nl108/chm.htm (http://www.libertybasicuniversity.com/lbnews/nl108/chm.htm)

And this gives information on how to create the [MAP] and [ALIAS] sections: https://support.microsoft.com/de-de/help/189453/how-to-prepare-html-help-files-for-context-sensitive-help (https://support.microsoft.com/de-de/help/189453/how-to-prepare-html-help-files-for-context-sensitive-help)

Creating chm help is much easier if you use a help authoring tool, such as HelpNDoc or HelpScribble - almost like writing a text in Word. The basic version of HelpNDoc is free, sometimes the Pro version is available at a high discount at BitsDuJour - please use Google to find these sites, I don't want to make too much advertisement for them.
Title: Re: Problem adding chm help to an application
Post by: msimeon on October 06, 2017, 09:37:59 am
@wp

Many thanks for the very comprehensive reply.  It should be most helpful for me to find my way.
MS
Title: Re: Problem adding chm help to an application
Post by: serbod on October 06, 2017, 11:46:58 am
I did some fixes and improvements to LHelp - https://github.com/serbod/lazhelp

Internal HTML pages representation depends on IPro package and also need some fixing.
Title: Re: Problem adding chm help to an application
Post by: wp on October 06, 2017, 11:55:45 am
Why don't you provide a patch?
Title: Re: Problem adding chm help to an application
Post by: serbod on October 06, 2017, 12:10:53 pm
Why don't you provide a patch?

I contacted to mantainer, Andrew Haines.
Title: Re: Problem adding chm help to an application
Post by: JuhaManninen on October 06, 2017, 02:36:36 pm
I contacted to mantainer, Andrew Haines.
He has not been active lately. A patch for Lazarus sources would be the right way to go. Use "git format-patch" to create it.
Title: Re: Problem adding chm help to an application
Post by: marcov on October 06, 2017, 02:46:40 pm
Please refrain from excessive reformatting. While there is a small benefit visually, it usually complicates sifting through version system history more than it is worth.
Title: Re: Problem adding chm help to an application
Post by: serbod on October 06, 2017, 03:45:04 pm
Please refrain from excessive reformatting. While there is a small benefit visually, it usually complicates sifting through version system history more than it is worth.

That's not so easy, nice formatting and naming greatly helps to detect and avoid many bugs. Also, it helps maintain code, decrease time, needed to read code and get it designation. Difficulties encountered only once, when merging to SVN. And then code will be read by users countless times.
Title: Re: Problem adding chm help to an application
Post by: marcov on October 06, 2017, 04:07:43 pm
Please refrain from excessive reformatting. While there is a small benefit visually, it usually complicates sifting through version system history more than it is worth.

That's not so easy, nice formatting and naming greatly helps to detect and avoid many bugs.

True. But most of those are getting to a basic, minimal level, and not driving that to extremes. Worse, then you also get into the realm of personal taste rather than safe programming practices.

Quote
Also, it helps maintain code, decrease time, needed to read code and get it designation. Difficulties encountered only once, when merging to SVN. And then code will be read by users countless times.

And then again by merging to fixes, and then again when tracing the history of a bug. Actually there will be more developers doing that then users studying the code.
Title: Re: Problem adding chm help to an application
Post by: serbod on October 06, 2017, 04:21:21 pm
What "safe programming practices"? I personnaly follows CERT Coding Standards and Embarcadero Object Pascal Style Guide. And there is no rules, that restrict changes in SVN because it difficults changes history studing.
Title: Re: Problem adding chm help to an application
Post by: marcov on October 06, 2017, 06:14:11 pm
What "safe programming practices"?

I just meant somewhat decent formatting and sane variablenames. While it is generally a good idea, how far you must push this, and if you should modify existing code is often a matter of taste, and doesn't have too much to do with bug avoidance anymore.

Quote
I personnaly follows CERT Coding Standards and Embarcadero Object Pascal Style Guide. And there is no rules, that restrict changes in SVN because it difficults changes history studing.

Well, they only document new code, not the tradeoffs for changing existing code in a team.


Title: Re: Problem adding chm help to an application
Post by: msimeon on October 07, 2017, 09:56:47 am
@wp

Thanks again, I finally got it working.

Title: Re: Problem adding chm help to an application
Post by: msimeon on October 07, 2017, 11:47:37 am
@serbod
I did some fixes and improvements to LHelp - https://github.com/serbod/lazhelp

Internal HTML pages representation depends on IPro package and also need some fixing.

Can you now display correctly a chm file with images ?  This was the issue that started this discussion ! I did dowwnload and compiled your improved lhelp but to me it did not solve that particular problem.
Title: Re: Problem adding chm help to an application
Post by: wp on October 07, 2017, 11:58:11 am
The images embedded in the chmdemo which I posted above are displayed by the lhelp version which comes with Lazarus. lhelp (or to be more precise: the TIpHtmlPanel), however, has lots of trouble positioning them correctly, and it also ignores a lot of the css instructions.

Does the Windows chm viewer display the images? Did you add the png files to the help project?
Title: Re: Problem adding chm help to an application
Post by: msimeon on October 07, 2017, 03:56:20 pm
@wp

The images embedded in the chmdemo which I posted above are displayed by the lhelp version which comes with Lazarus. lhelp (or to be more precise: the TIpHtmlPanel), however, has lots of trouble positioning them correctly, and it also ignores a lot of the css instructions.

Does the Windows chm viewer display the images? Did you add the png files to the help project?

Yes, I compiled the chm file with Microsoft Help Workshop, and displayed using the Windows chm viewer, thanks to your detailed guidance.  The png files are included in the help project.
Title: Re: Problem adding chm help to an application
Post by: wp on October 07, 2017, 07:32:36 pm
- 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
Returning to your original question: Could you post the complete Microsoft HelpWorkshop project, i.e. hhp file plus all files needed to build the chm? Pack everything into a common zip which you can upload here. All my tests show that lhelp is able to display embedded images.
Title: Re: Problem adding chm help to an application
Post by: msimeon on October 08, 2017, 12:23:23 pm
@wp

Returning to your original question: Could you post the complete Microsoft HelpWorkshop project, i.e. hhp file plus all files needed to build the chm? Pack everything into a common zip which you can upload here. All my tests show that lhelp is able to display embedded images.

Here it is
Title: Re: Problem adding chm help to an application
Post by: wp on October 08, 2017, 01:37:34 pm
Running (almost) perfectly here - see screenshot. What is your Lazarus version? (I tested trunk, 1.8RC4 and 1.6.4 - they work correctly, 1.4.4 hangs (but I am not 100% sure if this is still the original version), 1.2 displays your help file with the images but does not update the content tree).

There are a couple of issues though:

/1/
a UTF8 issue on the index page (dettes_index.html): This is because your source files contain this meta tag:
Code: [Select]
    <meta content="text/html; charset=windows-1252" http-equiv="content-type">You are mixing up html and css syntax here. Not sure if this is generally allowed, but IpHtmlPanel does not seem to like it. The correct line would be:
Code: [Select]
    <meta content="text/html" charset="windows-1252" http-equiv="content-type">BTW: better to use UTF8 encoding.

/2/
a missing space if you have a linebreak after an </a> tag (see screenshot, where the popup hint is shown). As a workaround, until this is fixed, pull the space into the <a> tag, or move a word from the following line behind the </a>, like this:
Code: [Select]
    <p>Les donnĂ©es nĂ©cessaires au <a href="description.html#calculs">calcul</a> sont: </p>
Title: Re: Problem adding chm help to an application
Post by: msimeon on October 08, 2017, 02:02:08 pm
@wp

I am using Lazarus 1.64; as I am new at this game (I am an amateur programmer, and more familiar with Eclipse, Java and XText) it is quite possible that lhelp did not work properly when I tried it out because my chm was not correct.  I'll go back to it, after adjusting my html files as per your comments.

Thanks again for your support
Title: Re: Problem adding chm help to an application
Post by: msimeon on October 08, 2017, 06:25:33 pm
@wp

Attached is a very simplistic test of displaying my chm file using lhelp.exe ; it asssumes lhelp.exe is found in the same directory as the application (but it is too big to be included in the attachmeny), together with the chm file.
It does display the images (unlike my earlier attempt)
It ignores some of the css instructions
Links within html files are not working
Title: Re: Problem adding chm help to an application
Post by: wp on October 08, 2017, 06:52:36 pm
Links within html files are not working
You mean something like this: If I click on the link "options" in the second paragraph on the page which opens when the node "Specifications" > "Descriptions" in the left Contents tree is clicked, the correct page is opened but the page does not scroll down to show the linked paragraph "Options"?

I could imagine that this is a bug in the IpHTMLPanel.

Unfortunately, I don't have the time at the moment to look at this issue in detail. Please write a report to the bugtracker that it is not forgotten. Attach this demo project to the report, as well as the source files creating the chm files.
Title: Re: Problem adding chm help to an application
Post by: msimeon on October 09, 2017, 10:22:13 am
@wp

Links within html files are not working
You mean something like this: If I click on the link "options" in the second paragraph on the page which opens when the node "Specifications" > "Descriptions" in the left Contents tree is clicked, the correct page is opened but the page does not scroll down to show the linked paragraph "Options"?

I could imagine that this is a bug in the IpHTMLPanel.

Unfortunately, I don't have the time at the moment to look at this issue in detail. Please write a report to the bugtracker that it is not forgotten. Attach this demo project to the report, as well as the source files creating the chm files.

Done ! Report number is 0032526.  I also created report 0032525 missing the attached file. It should be deleted
Title: Re: Problem adding chm help to an application
Post by: serbod on October 17, 2017, 02:42:54 pm
Who is author of chmmaker?
Title: Re: Problem adding chm help to an application
Post by: molly on October 17, 2017, 03:02:15 pm
Who is author of chmmaker?
Take a pick (https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/tools/chmmaker/?root=lazarus) out of one of the many contributors ?
Title: Re: Problem adding chm help to an application
Post by: wp on October 17, 2017, 03:28:37 pm
The first commit (dated Oct 30 2008) was by Andrew Haines.
Title: Re: Problem adding chm help to an application
Post by: serbod on October 17, 2017, 04:47:21 pm
Thanks, i did another bunch of fixes and improvements to CHM-related packages.

Also, i want try to use HtmlViewer (https://github.com/BerndGabriel/HtmlViewer) as HTML view component. Is their licence is acceptable for Lasarus? It looks like GPL, but i don't sure, in DitherUnit.PAS is something about non-commercial use.
Title: Re: Problem adding chm help to an application
Post by: wp on October 17, 2017, 05:38:02 pm
As already mentioned above, you must provide a proper patch (relative to the current trunk version) and write a report to bugtracker. The maintainer must be able to evaluate what you changed; without a patch this is not possible. And please provide a detailed description of your modifications ("Fixes and improvements of CHM-related packages" would be ok for the headline, but certainly not for the description).

Sorry to be so nitpicking, but since Andrew seems to have retired from this activity somebody else must take care of it, and the more you help this person to understand and evaluate the fixes the more likely it is that your code is accepted.

I cannot comment on you intention to replace IpHtmlPanel with HTMLviewer. IpHtmlPanel is still rather buggy, but it is established in the help popup hints of Lazarus, therefore I think there will be some resistance. Please post this question to the mailing list because many developers do not read the forum.
Title: Re: Problem adding chm help to an application
Post by: serbod on October 18, 2017, 02:09:46 pm
Currently, i can't provide patch for trunk, because made too many changes, and that patch will contain almost whole source lines. There is lot minor changes, related to code formatting, naming and commenting. When i did that, i found some memory leaks and range violations. For example, s[1] when s='' and calling freed, but not nil-ed objects. Maybe, that solve some runtime problems. In some places lacks of documentation or comments caused wrong parameters (full path where need relative, upper/mixed case). Additional checks and sanitize added, changed access for some methods (from public to protected), some properties and parameters made read-only.

IpHtmlPanel is very strange choise for pop-up hints. It contain at least 30K lines of code and provide interactive HTML DOM model. It good for HTML pages with complex markup, but too much for simple pop-up hint.

Maybe better use RichView, that contain 3K lines of code, and provide only auto-alligned list of text blocks and drawable objects (lines, pictures, any LCL visual components). That list can be imported from HTML/RTF/PDF/TEX/BBCode/Markdown by simple one-way parsers.
TinyPortal © 2005-2018