Recent

Author Topic: chm help file hangs after calling Application.Initialize  (Read 9433 times)

dculp

  • Full Member
  • ***
  • Posts: 129
chm help file hangs after calling Application.Initialize
« on: January 28, 2017, 12:52:55 pm »
I'm calling a chm help file with
Code: Pascal  [Select][+][-]
  1. ZResult:= HtmlHelpA(0,pchar(helpfilename),HH_DISPLAY_TOPIC,ptruint(pchar(htmltopic)));
  2.  

The chm file loads and runs as expected. If the above call is preceded by Application.Initialize then the chm file still loads. However, attempting a search in the chm Search tab then causes the chm window to hang (hourglass - "not responding"). The test program below shows this problem (see comments there). (The test program should be run with the attached Small_demo_1a.chm file.)

Notes:
1. If you start  Small_demo_1a.chm by double-clicking on it then the chm Search runs OK. Therefore, the problem doesn't seem to be with the chm file itself.
2. Application.Initialize is not needed for this test program. However, it is needed for the actual application in order to use Windows Open/Save dialogs.

Lazarus 1.6 (FPC 3.0.0)
Windows 7 Pro

Thanks for any suggestions.
Don C.

Code: Pascal  [Select][+][-]
  1. Program CHM_help_21a;
  2. {Small example/test of the html help OCX.
  3.  Marco van de Voort (C) 2009 - heavily modified}
  4.  
  5. {$mode objfpc}{$H+}
  6.  
  7. uses
  8.   Forms, Interfaces,  // Requires  LCL package (not LCLbase)
  9.         // Above are required for Application.Initialize & exception handling
  10.  
  11.   htmlhelp, { \Lazarus\fpc\3.0.0\source\packages\winunits-base\src\htmlhelp.pp }
  12.   crt;
  13.  
  14. var
  15.    HelpfileName: AnsiString = 'Small_demo_1a.chm';
  16.    htmltopic   : AnsiString = 'Subtopic1.htm'; // the extension must be htm, not html
  17.    ZResult: Integer;
  18.  
  19. begin
  20. clrscr;
  21. writeln('Test for CHM help Search.');
  22. writeln('When the CHM test file loads, access the Search tab.');
  23. writeln('Enter any search phrase and click List Topics.');
  24. writeln('The CHM file will hang due to Application.Initialize.');
  25. writeln('However, this window will remain active.');
  26. write('Press Enter to proceed ... '); readln;
  27.  
  28. Application.Initialize; // Causes CHM file to hang after executing a search in the Search tab
  29.  
  30. { Application.Initialize is needed for Dialogs.pas (e.g., -
  31.       Dialog:= TSaveDialog.Create(nil); // where var Dialog: TOpenDialog;
  32.       Dialog.Execute;
  33.   See http://forum.lazarus.freepascal.org/index.php/topic,34998.0.html }
  34.  
  35. ZResult:= HtmlHelpA(0,pchar(helpfilename),HH_DISPLAY_TOPIC,ptruint(pchar(htmltopic)));
  36.    { See \Lazarus\fpc\3.0.0\source\packages\winunits-base\src\htmlhelp.pp }
  37.  
  38. writeln;
  39. writeln('Showing topic ', htmltopic);
  40. writeln('ZResult = ', ZResult);
  41. Write('Press Enter (in console window) to exit ... '); readln;
  42. end.
  43.  

« Last Edit: January 28, 2017, 01:07:48 pm by dculp »

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: chm help file hangs after calling Application.Initialize
« Reply #1 on: January 28, 2017, 02:39:22 pm »
I would not use that code anymore, especially since MS deprecated its use (IONS AGO!!!).
It is not even provided in a standard Windows since Vista. It is a separate install/download.
For windows 10+ it is not even provided AT ALL....

But there is a really good CHM package in the standard distribution of FPC.
You will find it in packages/chm and it is also cross-platform.

Furthermore: that is really, really badly written code.
If you need application.initialize, call it as the first line.
You are also mixing GUI elements with a command line appilcation.

Oh well, some...

Anyway: just use the CHM package and move the application.initialize to its proper place.
And try to clean up your code.
« Last Edit: January 28, 2017, 02:46:34 pm by Thaddy »
Specialize a type, not a var.

dculp

  • Full Member
  • ***
  • Posts: 129
Re: chm help file hangs after calling Application.Initialize
« Reply #2 on: January 28, 2017, 02:58:11 pm »
I would not use that code anymore, especially since MS deprecated its use (IONS AGO!!!).
It is not even provided in a standard Windows since Vista. It is a separate install/download.
For windows 10+ it is not even provided AT ALL....

When you refer to "that code", is this the
HtmlHelpA(0,pchar(helpfilename),HH_DISPLAY_TOPIC,ptruint(pchar(htmltopic)));
or is it the
Application.Initialize?


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: chm help file hangs after calling Application.Initialize
« Reply #3 on: January 28, 2017, 03:03:46 pm »
I would not use that code anymore, especially since MS deprecated its use (IONS AGO!!!).
Yes, chm was deprecated in Vista, but the successor is limited and not open (requires fee/developer subscription the last time I checked), and I doubt you could name it.

So chm is still the default MS client help tech for applications

Quote
It is not even provided in a standard Windows since Vista. It is a separate install/download.
For windows 10+ it is not even provided AT ALL....

You are confusing .hlp with .chm. 

« Last Edit: January 28, 2017, 03:07:43 pm by marcov »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: chm help file hangs after calling Application.Initialize
« Reply #4 on: January 28, 2017, 03:26:44 pm »
The chm file loads and runs as expected. If the above call is preceded by Application.Initialize then the chm file still loads. However, attempting a search in the chm Search tab then causes the chm window to hang (hourglass - "not responding"). The test program below shows this problem (see comments there). (The test program should be run with the attached Small_demo_1a.chm file.)

I can reproduce, but can't really say what causes it. It could be a bug in the MS helpviewer (due to an enormously spartan CHM), but also in lazarus. I would at the very least expand the chm to a more wellformed, or use one from an existing program, to test if it is lazarus/LCL or the chm

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: chm help file hangs after calling Application.Initialize
« Reply #5 on: January 28, 2017, 03:35:15 pm »
For windows 10+ it is not even provided AT ALL....
This is not correct. I have Win10 and can open chm files by doubleclicking (I can't remember whether I had to install something additionally to the system, probably I had to...).  I also have some projects in which the chm files are opened correctly in a similar way as shown by the OP. And don't advertise the CHM package too much: although it has improved there are still lots of annoyances.

dculp

  • Full Member
  • ***
  • Posts: 129
Re: chm help file hangs after calling Application.Initialize
« Reply #6 on: January 28, 2017, 04:11:08 pm »
You are also mixing GUI elements with a command line appilcation.

I'm updating a character-based app from Turbo Pascal 7 so that it will run under Win7+. It will remain character-based (no panels, components, etc.). However, I want to use Windows File Open/Save dialogs. So, yes, I'm mixing GUI elements with my application. Hence, I need Application.Initialize.

But there is a really good CHM package in the standard distribution of FPC.
You will find it in packages/chm and it is also cross-platform.

I'm using HelpNDoc (commercial) and the MS HTML Help Compiler (hhc.exe) to generate the chm file. Will the FPC CHM package help me beyond this? If so, can you point me to the specific code?

Do you think there's a problem with the following?
   HtmlHelpA(0,pchar(helpfilename),HH_DISPLAY_TOPIC,ptruint(pchar(htmltopic)));
If not, what might cause the chm window to hang when Application.Initialize is called before the above? Could I need a new or different compiler directive?



dculp

  • Full Member
  • ***
  • Posts: 129
Re: chm help file hangs after calling Application.Initialize
« Reply #7 on: January 28, 2017, 04:40:08 pm »
The chm file loads and runs as expected. If the above call is preceded by Application.Initialize then the chm file still loads. However, attempting a search in the chm Search tab then causes the chm window to hang (hourglass - "not responding"). The test program below shows this problem (see comments there). (The test program should be run with the attached Small_demo_1a.chm file.)

I can reproduce, but can't really say what causes it. It could be a bug in the MS helpviewer (due to an enormously spartan CHM), but also in lazarus. I would at the very least expand the chm to a more wellformed, or use one from an existing program, to test if it is lazarus/LCL or the chm

I get the same result when I use Avast5_1033.chm (Avast antivirus file, 1/2/2017) so the problem doesn't seem to be with the chm files.

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: chm help file hangs after calling Application.Initialize
« Reply #8 on: January 28, 2017, 05:08:20 pm »
Instead of calling HtmlHelp function from a console program I'd prefer to open the file in hh.exe by means of a separate process. The next code works fine, please copy rtl.chm from the Lazarus/Docs/chm folder to the folder of the following demo:

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   SysUtils, Process, Classes;
  7.  
  8. const
  9.   CHMFile = 'rtl.chm';
  10.   TOPIC = 'index';
  11.  
  12. var
  13.   prc: TProcess;
  14.  
  15. begin
  16.   prc := TProcess.Create(nil);
  17.   try
  18.     prc.CommandLine := Format('hh.exe mk:@MSITStore:%s::/system/%s.html', [CHMFile, TOPIC]);
  19.     prc.Options := prc.Options + [poWaitOnExit];
  20.     prc.Execute;
  21.   finally
  22.     prc.Free;
  23.   end;
  24. end.

See this (http://wiki.freepascal.org/Executing_External_Programs#TProcess) for more details on TProcess.

If you want to go cross-platform then you should use the Lazarus CHM viewer, it is called lhelp and is in folder comonents/chmhelp/lhelp. Load the project into Lazarus and compile it (it requires that you have installed the packages lhelpcontrolpkg.lpk and TurboPowerIpro.lpk). ATM I don't know the calling convention how to open a specific topic. But adding the chm file name as a parameter opens the specific chm file at least.

P.S.
HelpNDoc is great!
« Last Edit: January 28, 2017, 05:20:19 pm by wp »

dculp

  • Full Member
  • ***
  • Posts: 129
Re: chm help file hangs after calling Application.Initialize
« Reply #9 on: February 02, 2017, 03:02:17 am »
Instead of calling HtmlHelp function from a console program I'd prefer to open the file in hh.exe by means of a separate process. The next code works fine ..

Yes, this will open the chm file. However, is there any way to link a topic in my application to a particular topic in the chm? (This is an absolute requirement for my application.) This should preferably be done without having to re-invoke the chm each time a new topic is linked. Otherwise, the chm's forward and back buttons wouldn't work and the Contents tab would revert to its default state. However, this might not be totally unacceptable.

If you want to go cross-platform then you should use the Lazarus CHM viewer, it is called lhelp and is in folder comonents/chmhelp/lhelp. Load the project into Lazarus and compile it (it requires that you have installed the packages lhelpcontrolpkg.lpk and TurboPowerIpro.lpk). ATM I don't know the calling convention how to open a specific topic. But adding the chm file name as a parameter opens the specific chm file at least.

P.S.
HelpNDoc is great!

Unfortunately, when I try to open any HelpNDoc chm (including HelpNDoc's own chm help file) I get a Lhelp error "Resource unavailable:ms-its:". This seems to be a known problem. Search "unavailable" here --
http://forum.lazarus-ide.org/index.php?topic=30663.105
http://forum.lazarus.freepascal.org/index.php?topic=30663.110;wap2
Interestingly, I tried several non-HelpNDoc chms and none have this problem. However, I'm wedded to HelpNDoc at this point.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: chm help file hangs after calling Application.Initialize
« Reply #10 on: February 02, 2017, 08:31:55 am »
Yes, this will open the chm file. However, is there any way to link a topic in my application to a particular topic in the chm?
Have you tried to change constant TOPIC = 'index' to something else?
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

dculp

  • Full Member
  • ***
  • Posts: 129
Re: chm help file hangs after calling Application.Initialize
« Reply #11 on: February 02, 2017, 11:11:55 am »
Yes, this will open the chm file. However, is there any way to link a topic in my application to a particular topic in the chm?
Have you tried to change constant TOPIC = 'index' to something else?

I don't know what topics (specific topic names) are available in rtl.chm. Instead I have tried each of the following in project1 (WP's post on 1/28) using Small_demo_1a.chm (from my original post) for the topic Subtopic1 --
   TOPIC = 'Subtopic1.html';
   TOPIC = 'Subtopic1.htm';
   TOPIC = 'Subtopic1';
   TOPIC = 'index'; // just to see effect
   TOPIC = ''; // just to see effect
In all cases when the chm loaded it reported "This page can't be displayed". This happens whether the chm initially opens to the Contents tab or the Search tab. However, once the chm has loaded this topic will display correctly by clicking on it in Contents tab (under Introduction).

balazsszekely

  • Guest
Re: chm help file hangs after calling Application.Initialize
« Reply #12 on: February 02, 2017, 11:18:25 am »
I did run a few tests and apparently you need a dummy window. So create one, pass the handle to HtmlHelpA and you're good to go. More over you can hide or AlphaBlend it, so visually the result is the same as in your original project.

dculp

  • Full Member
  • ***
  • Posts: 129
Re: chm help file hangs after calling Application.Initialize
« Reply #13 on: February 02, 2017, 11:44:50 am »
I did run a few tests and apparently you need a dummy window. So create one, pass the handle to HtmlHelpA and you're good to go. More over you can hide or AlphaBlend it, so visually the result is the same as in your original project.

For the tests that you ran, are you referring to my original code (where the chm hangs upon searching) or WP's code (trying to load a specific help topic)?
How do I create a dummy window? (Note that my application is non-GUI if this makes any difference.)
How would I hide the dummy window?
Could you provide some demo code (much appreciated)?

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: chm help file hangs after calling Application.Initialize
« Reply #14 on: February 02, 2017, 11:56:38 am »
In all cases when the chm loaded it reported "This page can't be displayed". This happens whether the chm initially opens to the Contents tab or the Search tab.
I don't know, but did you enter the topic correctly? Sometimes the extension is .html, sometimes only .htm. And in my sample there is a path "/system/" in front of the topic name. Please compile the program chmls (in fpc/packages/chm). Run it with the chm file as a parameter and it will list you all contained topics along with extension and path.

[EDIT]
I played with my demo a bit and modified it such that it accepts filename and topic as parameter:
Code: Pascal  [Select][+][-]
  1. program showchm;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   SysUtils, Process, Classes;
  7.  
  8. var
  9.   prc: TProcess;
  10.   chm: String;
  11.   topic: String;
  12.   s: String;
  13.  
  14.   procedure Syntax;
  15.   begin
  16.     WriteLn('USAGE:    showchm chmfile [topic incl path and extension]');
  17.     WriteLn('EXAMPLE:  showchm rtl.chm    ---> shows index.html');
  18.     WriteLn('          showchm rlt.chm /x86/writeportw.html');
  19.     Halt;
  20.   end;
  21. begin
  22.   if ParamCount = 0 then
  23.     Syntax;
  24.  
  25.   chm := ParamStr(1);
  26.   if ParamCount = 1 then
  27.     topic := '/system/index.html'
  28.   else begin
  29.     topic := ParamStr(2);
  30.     if topic[1] <> '/' then topic := '/' + topic;
  31.   end;
  32.  
  33.   prc := TProcess.Create(nil);
  34.   try
  35.     s := Format('hh.exe mk:@MSITStore:%s::%s', [chm, topic]);
  36.     prc.CommandLine := s;
  37.     prc.Options := prc.Options + [poWaitOnExit];
  38.     prc.Execute;
  39.   finally
  40.     prc.Free;
  41.   end;
  42. end.  
Call it with the filename of the chm file (can contain path) and with the topic including its path and extension (see output of chmls). It works with the chm files coming with Lazarus, as well as with those created by HelpNDoc.
« Last Edit: February 02, 2017, 01:04:12 pm by wp »

 

TinyPortal © 2005-2018