4

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.

4

4 回答 4

5

假设您有两个名为“Help File 1.chm”和“Help File 2.chm”的帮助文件,并且您正在从 Delphi 代码中打开这些帮助文件。

要打开帮助文件 1,以下代码将起作用:

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

要打开帮助文件 2,以下代码将起作用:

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

但是要同时打开两个文件,下面的代码会导致两个帮助窗口都挂起

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;

解决方案:

问题是由帮助文件名中有空格引起的。

从文件名中删除空格将解决问题。

以下代码可以正常工作:

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

  Application.HelpFile := 'HelpFile2.chm';
  Application.HelpContext(0);
end;
于 2008-09-18T06:27:52.320 回答
1

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?

于 2008-09-18T00:18:38.663 回答
1

试过了。只是工作。

于 2008-09-18T00:47:08.440 回答
0

对这里的帮助文件没有经验,对 Vista 更是如此,但我可以为您提供一个可能的解决方法......

构建第二个应用程序,其唯一工作是打开帮助文件。您可以将帮助文件名作为命令行参数传递。

您可以从主应用程序轻松检查此帮助应用程序是否正在运行。这将使您完全控制,因为您可以决定是否要

  • 在打开辅助帮助之前发送消息以关闭帮助应用程序
  • 允许多个帮助应用程序实例允许同时打开不同的帮助文件
  • 允许帮助在您的应用程序关闭后保持打开状态,或者您是否要向它发送消息以关闭它

您还可以检查帮助应用程序的实例是否已经打开了请求的帮助文件,并决定是否要允许第二次打开它,或者只是将现有实例置于前台。

如前所述,这是一种解决方法 - 如果它是您唯一的选择,请告诉我您是否需要代码示例。否则我会保持这篇文章的干净(并在短期内节省自己的时间),而不是用不必要的来源弄乱它

于 2008-09-17T09:05:36.783 回答