简体   繁体   English

Delphi XE2:跳转到CHM中的锚点?

[英]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? 在Delphi XE2程序中,如何跳转到CHM帮助文件主题中的锚点? The anchor has the following format (extracted from the source of the topic page in HTML HelpViewer showing the CHM file): 锚具有以下格式(从HTML HelpViewer中显示CHM文件的主题页面的源中提取):

<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. 不幸的是,这不起作用:它确实跳到了这个主题,但只是跳到主题的顶部,而不是主题,这是几个向下滚动的页面。

Jumping to an anchor in CHM 跳到CHM的锚点
Tested with Delphi2010 - DelphiXE2 - Windows XP 使用Delphi2010测试 - DelphiXE2 - Windows XP

How to jump to an anchor in a chm file (Compiled HTML Help) with Delphi. 如何使用Delphi跳转到chm文件(Compiled HTML Help)中的锚点

Yes, it is possible with a HtmlHelp() command to jump to an anchor. 是的,可以使用HtmlHelp()命令跳转到锚点。
<a name="my_anchor"></a>

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

The LINK in : Overview.htm 链接: Overview.htm

  • Note: This link is not needed to jump via the delphi program to 注意:通过delphi程序跳转到不需要此链接
    the anchor.(Only for testing). 锚点。(仅用于测试)。

Overview.htm 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 ANCHOR在: 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: 以下是更多信息和测试程序:

在此输入图像描述

Run Project1.exe and select without : 运行Project1.exe并选择不:

在此输入图像描述

The Unit1.pas / the command Unit1.pas /命令

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 单击按钮Overview.htm#UsingtheMenus

The Result: 结果:

The Help file is opened and the overview.htm appears. 将打开帮助文件并显示overview.htm It was jumped to the anchor. 它被跳到了锚点。

在此输入图像描述


Download source Project1.exe D2010 and XE2. 下载源Project1.exe D2010和XE2。
Download source sample.chm HtmlHelp project. 下载源sample.chm HtmlHelp项目。

Download 下载


Now let's test the other 2 Buttons 现在让我们测试其他2个按钮

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') 单击Button HelpKeyword('UsingtheMenus')

The Result: 结果:

The Help file is opened and the FirstTopic.htm appears. 将打开帮助文件并显示FirstTopic.htm The text UsingtheMenus is inserted into the searchfield. 文本UsingtheMenus插入searchfield。 No jump to the anchor! 没有跳到锚!


  • Click the Button HelpContext(IDH_UsingtheMenus)') 单击Button HelpContext(IDH_UsingtheMenus)')

The same result except the search box is empty. 除搜索框外,相同的结果为空。


The last 2 clicks demonstrate here: 最后2次点击演示如下:
There are no secret IDs or keywords in the file HelpFile2\\sample.chm available. HelpFile2 \\ sample.chm文件中没有秘密ID或关键字可用。


Now we change the help file so that in addition to Overview.htm#UsingtheMenus the other two methods lead to success. 现在我们更改帮助文件,以便除了Overview.htm#UsingtheMenus ,其他两种方法也会成功。

  • Close the App 'Project.exe` 关闭App'Project.exe`
  • Run 'Project.exe` again. 再次运行'Project.exe`。
  • Make sure the with is selected. 确保with被选中。

Now we use "sample.chm" in folder HelpFile\\ 现在我们在文件夹HelpFile中使用“sample.chm”
with the following settings. 使用以下设置。

sample.h sample.h

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

sample.ali sample.ali

IDH_Overview=Overview.htm
IDH_welcom=FirstTopic.htm
IDH_UsingtheMenus=Overview.htm#UsingtheMenus

sample.hcc 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 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. 如果我们编译“sample.chm”,我们会收到一条错误消息。

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 ! 这是正常的,因为文件“Overview.htm#Using theMenus”并不存在!

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') 单击Button HelpKeyword('UsingtheMenus')

在此输入图像描述

The Result: 结果:
The Help file is opened and the FirstTopic.htm appears. 将打开帮助文件并显示FirstTopic.htm The text UsingtheMenus is inserted into the searchfield. 文本UsingtheMenus插入searchfield。 The text UsingtheMenus is selected in the listbox 在列表框中选择文本UsingtheMenus
If you click Show 如果单击“ Show
It was jumped to the anchor. 它被跳到了锚点。


  • Click the Button HelpContext(IDH_UsingtheMenus)') 单击Button HelpContext(IDH_UsingtheMenus)')

The Result: 结果:

The Help file is opened and the overview.htm appears. 将打开帮助文件并显示overview.htm It was jumped to the anchor. 它被跳到了锚点。


  • click the Button Overview.htm#UsingtheMenus 单击按钮Overview.htm#UsingtheMenus

The Result: 结果:

Same result as above. 与上述结果相同。
The Help file is opened and the overview.htm appears. 将打开帮助文件并显示overview.htm 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. 将在明天继续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM