Skip to content Skip to sidebar Skip to footer

Delphi Xe2: Jumping To An Anchor In Chm?

In a Delphi XE2 program, how do I jump to an anchor inside a CHM help file topic? The anchor has the following format (extracted from the source of the topic page in HTML HelpViewe

Solution 1:

Jumping to an anchor in CHM Tested with Delphi2010 - DelphiXE2 - Windows XP

How to jump to an anchor in a chm file (Compiled HTML Help) with Delphi.

Yes, it is possible with a HtmlHelp() command to jump to an anchor.<a name="my_anchor"></a>

 HtmlHelp(0,hpPath+'::/Overview.htm#UsingtheMenus>main',HH_DISPLAY_TOPIC,DWORD(nil));

The LINK in : Overview.htm

  • Note: This link is not needed to jump via the delphi program to the anchor.(Only for testing).

Overview.htm

<!DOCTYPE HTMLPUBLIC"-//W3C//DTD HTML 3.2//EN"><HTML>
[...]
<BODYbgColor=#f7f8e2><H1>Overview</H1><AHREF="Overview.htm#UsingtheMenus">Using the Menus</A>
[...]

The ANCHOR in : Overview.htm

[...]
<ANAME="UsingtheMenus" </A><P><STRONG>Using the Menus and Toolbars</STRONG>
[...]

If anyone wants to try it.

Here are more information and a testprogram:

enter image description here

Run Project1.exe and select without :

enter image description here

The Unit1.pas / the command

procedure TForm1.Button2Click(Sender: TObject);
begin
    HtmlHelp(0,hpPath+'::/Overview.htm#UsingtheMenus>main',HH_DISPLAY_TOPIC,DWORD(nil));
end;
  • click the Button Overview.htm#UsingtheMenus

The Result:

The Help file is opened and the overview.htm appears. It was jumped to the anchor.

enter image description here


Download source Project1.exe D2010 and XE2. Download source sample.chm HtmlHelp project.

Download


Now let's test the other 2 Buttons

procedure TForm1.HelpKeywordClick(Sender: TObject);
begin
  Application.HelpKeyword('UsingtheMenus');
end;

procedure TForm1.HelpContextClick(Sender: TObject);
begin
  Application.HelpContext(IDH_UsingtheMenus);
end;
  • Click the Button HelpKeyword('UsingtheMenus')

The Result:

The Help file is opened and the FirstTopic.htm appears. The text UsingtheMenus is inserted into the searchfield. No jump to the anchor!


  • Click the Button HelpContext(IDH_UsingtheMenus)')

The same result except the search box is empty.


The last 2 clicks demonstrate here: There are no secret IDs or keywords in the file HelpFile2\sample.chm available.


Now we change the help file so that in addition to Overview.htm#UsingtheMenus the other two methods lead to success.

  • Close the App 'Project.exe`
  • Run 'Project.exe` again.
  • Make sure the with is selected.

Now we use "sample.chm" in folder HelpFile\ with the following settings.

sample.h

#define IDH_Creating_Projects_and_Topics 1005#define IDH_Overview 1003#define IDH_UsingtheMenus 1009

sample.ali

IDH_Overview=Overview.htmIDH_welcom=FirstTopic.htmIDH_UsingtheMenus=Overview.htm#UsingtheMenus

sample.hcc

<!DOCTYPE HTMLPUBLIC"-//IETF//DTD HTML//EN"><HTML>
[...]
        <LI><OBJECTtype="text/sitemap"><paramname="Name"value="Using the Menus"><paramname="Local"value="Overview.htm#UsingtheMenus"></OBJECT>   
[...]
</HTML>

sample.hhk

<!DOCTYPE HTMLPUBLIC"-//IETF//DTD HTML//EN"><HTML>
[...]
    <LI><OBJECTtype="text/sitemap"><paramname="Name"value="Using the Menus"><paramname="Name"value="Using the Menus"><paramname="Local"value="Overview.htm#UsingtheMenus"></OBJECT>   
[...]
</HTML>

If we compile "sample.chm", we get an error message.

HHC3015: Warning: An alias has been created to "Overview.htm#UsingtheMenus" but the file does not exist.

This is normal because the file "Overview.htm#UsingtheMenus" does not really exist !

Let's try it

Do not forget, the "Help window" after trying each of the following, to close again. Otherwise you can not track the different states.

  • Click the Button HelpKeyword('UsingtheMenus')

enter image description here

The Result: The Help file is opened and the FirstTopic.htm appears. The text UsingtheMenus is inserted into the searchfield. The text UsingtheMenus is selected in the listbox If you click Show It was jumped to the anchor.


  • Click the Button HelpContext(IDH_UsingtheMenus)')

The Result:

The Help file is opened and the overview.htm appears. It was jumped to the anchor.


  • click the Button Overview.htm#UsingtheMenus

The Result:

Same result as above. The Help file is opened and the overview.htm appears. It was jumped to the anchor.


Now we can use one of three methods to jump to the desired mark.


If anyone is interested in the functioning of the other buttons, then read on and get more information.

will be continued tomorrow.

Post a Comment for "Delphi Xe2: Jumping To An Anchor In Chm?"