tags:

views:

939

answers:

5

In Delphi, the application's main help file is assigned through the TApplication.HelpFile property. All calls to the application's help system then use this property (in conjunction with CurrentHelpFile) to determine the help file to which help calls should be routed.

In addition to TApplication.HelpFile, each form also has a TForm.HelpFile property which can be used to specify a different (separate) help file for help calls originating from that specific form.

If an application's main help window is already open however, and a help call is made display help from a secondary help file, both help windows hang. Neither of the help windows can now be accessed, and neither can be closed. The only way to get rid of the help windows is to close the application, which results in both help windows being automatically closed as well.

Example:

Application.HelpFile := 'Main Help.chm'; //assign the main help file name
Application.HelpContext(0); //dispays the main help window
Form1.HelpFile := 'Secondary Help.chm'; //assign a different help file
Application.HelpContext(0); //should display a second help window

The last line of code above opens the secondary help window (but with no content) and then both help windows hang.

My Question is this:

  1. Is it possible to display two HTMLHelp windows at the same time, and if so, what is the procedure to be followed?

  2. If not, is there a way to tell whether or not an application's help window is already open, and then close it programatically before displaying a different help window?

(I am Using Delphi 2007 with HTMLHelp files on Windows Vista)

UPDATE: 2008-09-18

Opening two help files at the same time does in fact work as expected using the code above. The problem seems to be with the actual help files I was using - not the code.

I tried the same code with different help files, and it worked fine.

Strangely enough, the two help files I was using each works fine on it's own - it's only when you try to open both at the same time that they hang, and only if you open them from code (in Windows explorer I can open both at the same time without a problem).

Anyway - the problem is definitely with the help files and not the code - so the original questions is now pretty much invalid.

UPDATE 2: 2008-09-18

I eventually found the cause of the hanging help windows. I will post the answer below and accept it as the correct one for future reference. I have also changed the questions title.

Oops... It seems that I cannot accept my own answer...

Please vote it up so it stays at the top.

A: 

Inexperienced with help files here, and even moreso with Vista, but I can offer you a possible workaround...

Build a second application whose only job is to open a help file. You can pass the help file name as a command line argument.

You can easily check from your main application whether this help application is running. This will give you full control, as you can decide whether you want to

  • Send a message to close the help application before opening the secondary help
  • Allow more than one instance of the help application to allow different help files to be open at the same time
  • Allow the help to remain open after your application closes, or whether you want to send a message to it to close it

You can also check whether an instance of the help application already has the requested help file open and decide whether you want to allow it to be opened a second time, or simply bring the existing instance to the foreground.

As stated, this is a workaround - if it turns out to be your only option let me know if you need code examples. Otherwise I'll keep this post clean (and save myself time in the short term) and not clutter it with unnecessary source

Graza
The workaround is a good idea, but having a second app just to open help files is probably overkill. You could achieve the same result using ShellExecute(Handle,'open',PChar('HelpFileName.chm'), nil, nil, SW_SHOWNORMAL);
A: 

I just tested that and it works, as expected, with the kind of code you tried.
Compiled in D2007/XP, ran in both XP and Vista without problem.

procedure TForm1.Button1Click(Sender: TObject);
begin
  Application.HelpFile:= 'depends.chm';
  Application.HelpContext(0);
  HelpFile:='GExperts.chm';
  Application.HelpContext(0);
end;

Both help files open and are alive and well....

Q1: Have you checked the validity of your help files?
Q2: Where did you place your code?

François
@FrnacoisYou are right - it does work. The problem seems to be with the actual help files I am using - not the code.
+1  A: 

Tried. Just works.

+2  A: 

Assuming you have to help files called "Help File 1.chm" and "Help File 2.chm" and you are opening these help files from your Delphi code:

To open Help File 1, the following code will work:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Application.HelpFile := 'Help File 1.chm';
  Application.HelpContext(0);
end;

To open Help File 2, the following code will work:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Application.HelpFile := 'Help File 2.chm';
  Application.HelpContext(0);
end;

But to open both files at the same time, the following code will cause both help windows to hang.

procedure TForm1.Button1Click(Sender: TObject);
begin
  Application.HelpFile := 'Help File 1.chm';
  Application.HelpContext(0);

  Application.HelpFile := 'Help File 2.chm';
  Application.HelpContext(0);
end;

SOLUTION:

The problem is caused by the fact that there are spaces in the help file names.

Removing the spaces from the file names will fix the problem.

The following code will work fine:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Application.HelpFile := 'HelpFile1.chm';
  Application.HelpContext(0);

  Application.HelpFile := 'HelpFile2.chm';
  Application.HelpContext(0);
end;
Hmmm... A Windoze problem or a Delphi problem? How to know?
Fabricio Araujo
A: 

I have a help file that gives the following error when I try HelpContext(0).

"The C:\Documents and Settings...\MyHelp.chm is not a Windows Help file, or the file is corrupted."

On FormCreate() ... // Help file setup helpFilePath := SnapDataModule.SnapConfig.getHelpFilePath(); if (fileexists(HelpFilePath)) then begin Application.HelpFile := HelpFilePath; Contents1.enabled := true; Contents1.visible := true; end;

On Contents1 menu click - Application.HelpContext(0);

if I open it with: ShellExecute(self.Handle,NIL,PChar(Application.helpfile),nil,nil,SW_SHOWNORMAL);

When I open it out side of Delphi it is fine.

What is wrong?

Joe