6

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 HelpViewer showing the CHM file):

<a name="my_anchor_id"></a>

I tried the following:

Application.HelpJump('MyTopicName.htm#my_anchor_id');

Unfortunately, this does not work: It does jump to this topic, but only to the top of the topic, not to the anchor, which is several scrolls down the page.

moskito-x
  • 11,832
  • 5
  • 47
  • 60
user1580348
  • 5,721
  • 4
  • 43
  • 105
  • Inside the HTML HelpViewer each topic is represented by its HTML file-name: "[TopicName].htm". That's why "Application.HelpJump('MyTopicName.htm');" does work. Shouldn't it be possible to deal with this internal HTML object like with an HTML object in a browser? – user1580348 Sep 05 '12 at 14:32
  • Yes it would be nice if you could. But you can't. You need A links. And topic IDs or topic names. – David Heffernan Sep 05 '12 at 14:33
  • How would you jump to an anchor inside a CHM topic using ALinks? – user1580348 Sep 05 '12 at 14:38
  • Well, I do it in my app with context IDs. So I use `Application.HelpContext`. If you used names rather than IDs then you'd use `HelpJump` I guess. – David Heffernan Sep 05 '12 at 14:44
  • may there be soem ?params plus javascript ? – Arioch 'The Sep 05 '12 at 14:48
  • David, how do you use HelpContext IDs? Since I use H&M, a HelpContext ID can be assigned to each anchor in H&M. I've tried to use "Application.HelpContext(5682)" (where 5682 is the HelpContext ID of the anchor in H&M), but it does not work. – user1580348 Sep 05 '12 at 14:56
  • That's exactly how you are meant to do it. Not sure why it's failing. Keep digging! – David Heffernan Sep 05 '12 at 14:57
  • When I use "Application.HelpContext(5682)" it has the same effect as "Application.HelpShowTableOfContents;": It just shows the first topic. – user1580348 Sep 05 '12 at 15:01
  • I guess the help file isn't configured quite right. I'm sure you can get tools to help debug things like that. – David Heffernan Sep 05 '12 at 15:02
  • I don't think so. H&M is a very mature program and it produces excellent results. – user1580348 Sep 05 '12 at 15:04
  • No, I'm not questioning H&M at all. It works fine. – David Heffernan Sep 05 '12 at 15:08
  • So what do you think isn't configured quite right? AFAIK there is nothing to configure in H&M regarding anchors. – user1580348 Sep 05 '12 at 15:23
  • Well I don't know. Try using another dev tool that can jump to context IDs. I'm sure it's easy with C#. See if you can connect to that ID from C#. Or find a good tool that lets you test ALINKs. It's been so long since I did this in anger, that I've forgotten which tools I've used in the past. – David Heffernan Sep 05 '12 at 15:32
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/16313/discussion-between-user1580348-and-david-heffernan) – user1580348 Sep 05 '12 at 17:36

1 Answers1

4

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 HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
[...]
<BODY bgColor=#f7f8e2>
<H1>Overview</H1>
<A HREF="Overview.htm#UsingtheMenus">Using the Menus</A>
[...]

The ANCHOR in : Overview.htm

[...]
<A NAME="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.htm
IDH_welcom=FirstTopic.htm
IDH_UsingtheMenus=Overview.htm#UsingtheMenus

sample.hcc

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

sample.hhk

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
[...]
    <LI> <OBJECT type="text/sitemap">
        <param name="Name" value="Using the Menus">
        <param name="Name" value="Using the Menus">
        <param name="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.

moskito-x
  • 11,832
  • 5
  • 47
  • 60
  • While it's very pretty with all the pictures and **bold** text and `formatted code`, I have no idea what exactly your answer says. Perhaps you could edit and add an answer at the top where it's clear what it is you're saying. What exactly is the answer to "jumping to an anchor in CHM" that future users will find here when searching finds this question and your answer? – Ken White Mar 16 '13 at 00:11
  • look at that part: `Conclusion Yes, it is possible with a HtmlHelp() command to jump to an anchor.` All comments say (in OP's question), you can not jump to an anchor with a Delphi command. `` @David said: `Yes it would be nice if you could. But you can't. You need A links. And topic IDs or topic names.` – moskito-x Mar 16 '13 at 00:26
  • My point is that you have to wade through everything else first, trying to find the part that is the *conclusion*. If someone finds this in a search in the future, they probably won't spend enough time with it before giving up and moving on to a different result. The *conclusion* should be at the top, and then you can add the details of *how your reached it* (which is almost a book). If you have to spend 10 minutes reading the answer to find out what it says, it's probably not worth looking at - put the conclusion first so the answer is clear. – Ken White Mar 16 '13 at 00:35
  • I just checked, and starting at the top of your answer I had to hit **three times** before I could see **conclusion**, which means *the answer is not clear*. There are **six more** keystrokes needed to reach the end of your answer from there. – Ken White Mar 16 '13 at 00:37
  • @moskito-x Thank you very much!!! The download link to your exemplary demo solved my problem! This is a perfect demo and a perfect solution!!! Thanks again! – user1580348 Jul 06 '13 at 14:35
  • @user1580348 : I'm glad you tried it and have come to success. Thank you also for the testing. – moskito-x Jul 06 '13 at 18:08