<p>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.</p>

<p>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.</p>

<p>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.</p>

<p>Example:</p>

<pre><code>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
</code></pre>

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

<p>My Question is this:</p>

<ol>
<li><p>Is it possible to display two HTMLHelp windows at the same time, and if so, what is the procedure to be followed?</p></li>
<li><p>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?</p></li>
</ol>

<p>(I am Using Delphi 2007 with HTMLHelp files on Windows Vista)</p>

<p><strong>UPDATE: 2008-09-18</strong></p>

<p>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.</p>

<p>I tried the same code with different help files, and it worked fine.</p>

<p>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).</p>

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

<p><strong>UPDATE 2: 2008-09-18</strong></p>

<p>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.</p>

<p>Oops... It seems that I cannot accept my own answer...</p>

<p>Please vote it up so it stays at the top.</p>

[{'answer_id': 81318, 'author': 'Graza', 'author_id': 11820, 'author_profile': 'https://Stackoverflow.com/users/11820', 'pm_score': 0, 'selected': False, 'text': "<p>Inexperienced with help files here, and even moreso with Vista, but I can offer you a possible workaround...</p>\n\n<p>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.</p>\n\n<p>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</p>\n\n<ul>\n<li>Send a message to close the help application before opening the secondary help</li>\n<li>Allow more than one instance of the help application to allow different help files to be open at the same time</li>\n<li>Allow the help to remain open after your application closes, or whether you want to send a message to it to close it</li>\n</ul>\n\n<p>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.</p>\n\n<p><em>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</em></p>\n"}, {'answer_id': 88869, 'author': 'Francesca', 'author_id': 9842, 'author_profile': 'https://Stackoverflow.com/users/9842', 'pm_score': 1, 'selected': False, 'text': "<p>I just tested that and <strong>it works, as expected,</strong> with the kind of code you tried.<br>\nCompiled in D2007/XP, ran in both XP and Vista without problem.</p>\n\n<pre><code>procedure TForm1.Button1Click(Sender: TObject);\nbegin\n  Application.HelpFile:= 'depends.chm';\n  Application.HelpContext(0);\n  HelpFile:='GExperts.chm';\n  Application.HelpContext(0);\nend;\n</code></pre>\n\n<p>Both help files open and are alive and well....</p>\n\n<p>Q1: Have you checked the validity of your help files?<br>\nQ2: Where did you place your code?</p>\n"}, {'answer_id': 89010, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Tried. Just works.</p>\n'}, {'answer_id': 90501, 'author': 'user5888', 'author_id': 5888, 'author_profile': 'https://Stackoverflow.com/users/5888', 'pm_score': 3, 'selected': False, 'text': '<p>Assuming you have two help files called "Help File 1.chm" and "Help File 2.chm" and you are opening these help files from your Delphi code.</p>\n\n<p>To open Help File 1, the following code will work:</p>\n\n<pre><code>procedure TForm1.Button1Click(Sender: TObject);\nbegin\n  Application.HelpFile := \'Help File 1.chm\';\n  Application.HelpContext(0);\nend;\n</code></pre>\n\n<p>To open Help File 2, the following code will work:</p>\n\n<pre><code>procedure TForm1.Button1Click(Sender: TObject);\nbegin\n  Application.HelpFile := \'Help File 2.chm\';\n  Application.HelpContext(0);\nend;\n</code></pre>\n\n<p>But to open both files at the same time, the following code will cause <strong>both help windows to hang</strong>.</p>\n\n<pre><code>procedure TForm1.Button1Click(Sender: TObject);\nbegin\n  Application.HelpFile := \'Help File 1.chm\';\n  Application.HelpContext(0);\n\n  Application.HelpFile := \'Help File 2.chm\';\n  Application.HelpContext(0);\nend;\n</code></pre>\n\n<p><strong>SOLUTION:</strong></p>\n\n<p>The problem is caused by the fact that there are <strong>spaces in the help file names</strong>.</p>\n\n<p>Removing the spaces from the file names will fix the problem.</p>\n\n<p>The following code will work fine:</p>\n\n<pre><code>procedure TForm1.Button1Click(Sender: TObject);\nbegin\n  Application.HelpFile := \'HelpFile1.chm\';\n  Application.HelpContext(0);\n\n  Application.HelpFile := \'HelpFile2.chm\';\n  Application.HelpContext(0);\nend;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/81243', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5888/']