Difference between revisions of "Add Help to Your Application/zh CN"

From Lazarus wiki
Jump to navigationJump to search
Line 1: Line 1:
{{添加帮助到你的应用程序Add Help to Your Application}}
+
{{Add Help to Your Application}}
  
LCL增加了帮助系统,允许 '''为你的程序创建帮助'''.
+
LCL带来一个帮助系统,允许你 '''为你自己的应用程序来创建帮助'''
  
 
== 快速开始 ==
 
== 快速开始 ==
示例位置: examples/helphtml/.
+
examples/helphtml/中打开示例。
  
 
演示如何使用HTML帮助控件。只需要拖拽它们到你的项目中。并设置并创建HTML文件。就可以给程序提供HelpKeyword。
 
演示如何使用HTML帮助控件。只需要拖拽它们到你的项目中。并设置并创建HTML文件。就可以给程序提供HelpKeyword。
Line 18: Line 18:
 
* A [[THelpViewer]] is a component that shows help content. For example a viewer for the mime type text/html can start a web browser.
 
* A [[THelpViewer]] is a component that shows help content. For example a viewer for the mime type text/html can start a web browser.
  
When help is requested, the LCL queries each registered [[THelpDatabase]] and each database can return a list of entries.
+
当请求帮助时,the LCL queries each registered [[THelpDatabase]] and each database can return a list of entries.
 
If several entries are returned, the LCL asks the user to choose an entry.
 
If several entries are returned, the LCL asks the user to choose an entry.
 
Then the LCL asks the database to show the help for the entry. The database extracts the help content and asks the LCL for a viewer that supports the mime type of the content.
 
Then the LCL asks the database to show the help for the entry. The database extracts the help content and asks the LCL for a viewer that supports the mime type of the content.
Line 29: Line 29:
 
Please see ${lazarusdir}/components/chmhelp/democontrol/.
 
Please see ${lazarusdir}/components/chmhelp/democontrol/.
  
You can write your own CHM files, e.g. with the now ancient Microsoft HTML Workshop or with the new Lazarus chmmaker tools in $(lazarusdir)/tools/chmmaker
+
你可以写你自己的CHM文件,例如,with the now ancient Microsoft HTML Workshop or with the new Lazarus chmmaker tools in $(lazarusdir)/tools/chmmaker
 
You can use a [[TCHMHelpDatabase]] control like the [[THTMLHelpDatabase]] control described below.
 
You can use a [[TCHMHelpDatabase]] control like the [[THTMLHelpDatabase]] control described below.
  
 
The advantages of using the CHM system are a smaller, self contained help file instead of multiple files. On the other hand, not every system has a CHM viewer installed by default, so you might want to include lhelp, a CHM viewer written in Pascal and included with the Lazarus sources (components/chmhelp/lhelp/lhelp.lpi).
 
The advantages of using the CHM system are a smaller, self contained help file instead of multiple files. On the other hand, not every system has a CHM viewer installed by default, so you might want to include lhelp, a CHM viewer written in Pascal and included with the Lazarus sources (components/chmhelp/lhelp/lhelp.lpi).
  
===Using LHelp===
+
===使用LHelp===
  
*Put a '''TLHelpConnector''' on your form.
+
*在你的窗体上放置一个'''TLHelpConnector'''
 
*Set '''LHelpPath''' with the name and location of the LHelp executable (this can be absolute, or relative to the application directory)
 
*Set '''LHelpPath''' with the name and location of the LHelp executable (this can be absolute, or relative to the application directory)
 
*Set '''AutoRegister''' to true
 
*Set '''AutoRegister''' to true
Line 71: Line 71:
 
To see the HTML help, see the lazarus example examples/helphtml/htmlhelp1.lpi.
 
To see the HTML help, see the lazarus example examples/helphtml/htmlhelp1.lpi.
  
=== Setup HTML help for your application ===
+
=== 为你的应用程序设置HTML帮助 ===
 
[[File:LazHtmlHelp.jpg|500px|thumb|right|Lazarus help items]]  
 
[[File:LazHtmlHelp.jpg|500px|thumb|right|Lazarus help items]]  
 
Adding HTML help to your application is easy:
 
Adding HTML help to your application is easy:
*Put a '''THTMLHelpDatabase''' on a form.
+
*在一个窗体上放置一个'''THTMLHelpDatabase'''
*Set '''AutoRegister''' to true.
+
*设置'''AutoRegister'''true
*Set '''KeywordPrefix''' to '''html/'''. It means all keywords must start with the string ''html/''.
+
*设置'''KeywordPrefix''''''html/''' 。它意味着所有关键字都必须以字符串''html/''为开头。
*Set '''BaseURL''' to '''file://yourhelp/'''. This will search the HTML files in the sub folder ''yourhelp''. You can specify full paths like ''file:///usr/lib/yourhelp/'' or an URL like ''http://www.yoursite.com/''.  
+
*设置'''BaseURL''''''file://yourhelp/'''. This will search the HTML files in the sub folder ''yourhelp''. You can specify full paths like ''file:///usr/lib/yourhelp/'' or an URL like ''http://www.yoursite.com/''.  
  
*Put a '''THTMLBrowserHelpViewer''' on the form. This component can start the user's default browser.
+
*在窗体上放置一个'''THTMLBrowserHelpViewer'''。这个组件可以启动用户的默认浏览器。
*Set '''AutoRegister''' to true.
+
*设置'''AutoRegister'''true
  
=== Creating a help entry ===
+
=== 创建帮助一个条目 ===
 
*Now create the subfolder ''yourhelp'' and create a html page ''yourhelp/edit1.html''. In case of a website, the help page should be accesible as ''http://www.yoursite.com/edit1.html''
 
*Now create the subfolder ''yourhelp'' and create a html page ''yourhelp/edit1.html''. In case of a website, the help page should be accesible as ''http://www.yoursite.com/edit1.html''
*Put a TEdit on a form.
+
*在一个窗体上放置一个TEdit。
*Set '''HelpType''' to ''htKeyword''
+
*设置'''HelpType'''''htKeyword''
*Set '''HelpKeyword''' to ''html/edit1.html''
+
*设置'''HelpKeyword'''''html/edit1.html''
  
 
When running the program you can focus the edit and press F1 to invoke the help. Under macOS the help key is Cmd-? (or Cmd+Shift+? depending on you keyboard layout).
 
When running the program you can focus the edit and press F1 to invoke the help. Under macOS the help key is Cmd-? (or Cmd+Shift+? depending on you keyboard layout).
Line 96: Line 96:
 
It shows a fully working example of an LCL application using [[fpGUI]]'s [http://fpgui.sourceforge.net/screenshots_apps.shtml DocView help viewer]. It shows context sensitive help and general help.
 
It shows a fully working example of an LCL application using [[fpGUI]]'s [http://fpgui.sourceforge.net/screenshots_apps.shtml DocView help viewer]. It shows context sensitive help and general help.
  
For example:
+
例如:
 
* Set focus to a specific control and press {{keypress|F1}}. It will show the help topic for that specific control.
 
* Set focus to a specific control and press {{keypress|F1}}. It will show the help topic for that specific control.
 
* Click the Help button and it will show the help topic for the dialog/form.
 
* Click the Help button and it will show the help topic for the dialog/form.

Revision as of 05:25, 23 December 2020

Deutsch (de) English (en) español (es) français (fr) русский (ru) 中文(中国大陆)‎ (zh_CN)

LCL带来一个帮助系统,允许你 为你自己的应用程序来创建帮助

快速开始

在 examples/helphtml/中打开示例。

演示如何使用HTML帮助控件。只需要拖拽它们到你的项目中。并设置并创建HTML文件。就可以给程序提供HelpKeyword。

如果要使用CHM帮助,请参照CHM帮助部分。

这里是一个非常好的演示 (chmdemo.zip): http://forum.lazarus.freepascal.org/index.php/topic,38487.msg261731.html#msg261731

帮助基础

LCL帮助包含两部分: 帮助数据库和查看器. 帮助数据库包含关键字 (ID, node, message, pascal, ...) 到帮助页面 (or help web site or...). 帮助查看器嗲用数据库向用户显示帮助信息.

  • A THelpDatabase manages content. It can be a collection of HTML pages or fpdoc XML files or a CHM file or a database or whatever.
  • A THelpViewer is a component that shows help content. For example a viewer for the mime type text/html can start a web browser.

当请求帮助时,the LCL queries each registered THelpDatabase and each database can return a list of entries. If several entries are returned, the LCL asks the user to choose an entry. Then the LCL asks the database to show the help for the entry. The database extracts the help content and asks the LCL for a viewer that supports the mime type of the content. Finally, the viewer shows the help content.

CHM

Context-sensitive CHM application help can be used from Lazarus 1.0 and later.

A demonstration program is included that shows how to include context-sensitive help using CHM and the lhelp CHM viewer (the same one that is used for IDE help by default). Please see ${lazarusdir}/components/chmhelp/democontrol/.

你可以写你自己的CHM文件,例如,with the now ancient Microsoft HTML Workshop or with the new Lazarus chmmaker tools in $(lazarusdir)/tools/chmmaker You can use a TCHMHelpDatabase control like the THTMLHelpDatabase control described below.

The advantages of using the CHM system are a smaller, self contained help file instead of multiple files. On the other hand, not every system has a CHM viewer installed by default, so you might want to include lhelp, a CHM viewer written in Pascal and included with the Lazarus sources (components/chmhelp/lhelp/lhelp.lpi).

使用LHelp

  • 在你的窗体上放置一个TLHelpConnector
  • Set LHelpPath with the name and location of the LHelp executable (this can be absolute, or relative to the application directory)
  • Set AutoRegister to true
// Example with both chm file and LHelp.exe in Application folder.
Procedure TForm1.FormCreate(Sender: TObject);
Begin
  If FileExists(ChangeFileExt(Application.ExeName, '.chm')) Then
  Begin
    CHMHelpDatabase1.Filename := ChangeFileExt(Application.ExeName, '.chm');
    CHMHelpDatabase1.Keyword := 'test';
    CHMHelpDatabase1.AutoRegister:=True;

    LHelpConnector1.LHelpPath := IncludeTrailingBackSlash(ExtractFileDir(Application.ExeName)) + 'lhelp.exe';
    LHelpConnector1.AutoRegister:=True;
  end
  Else
    mnuHelpMain.Enabled := False;
End; 

Procedure TForm1.Button1Click(Sender: TObject);
Begin
  If mnuHelpMain.Enabled Then  
    ShowHelpOrErrorForKeyword('','test/Main.html');
    //ShowTableOfContents;  (Not implemented for TCHMHelpDatabase)
End;


HTML

The LCL provides two components to use HTML files for help: THTMLHelpDatabase and THTMLBrowserHelpViewer. To see the HTML help, see the lazarus example examples/helphtml/htmlhelp1.lpi.

为你的应用程序设置HTML帮助

Lazarus help items

Adding HTML help to your application is easy:

  • 在一个窗体上放置一个THTMLHelpDatabase
  • 设置AutoRegister为 true 。
  • 设置KeywordPrefixhtml/ 。它意味着所有关键字都必须以字符串html/为开头。
  • 设置BaseURLfile://yourhelp/. This will search the HTML files in the sub folder yourhelp. You can specify full paths like file:///usr/lib/yourhelp/ or an URL like http://www.yoursite.com/.
  • 在窗体上放置一个THTMLBrowserHelpViewer。这个组件可以启动用户的默认浏览器。
  • 设置AutoRegister为 true 。

创建帮助一个条目

  • Now create the subfolder yourhelp and create a html page yourhelp/edit1.html. In case of a website, the help page should be accesible as http://www.yoursite.com/edit1.html
  • 在一个窗体上放置一个TEdit。
  • 设置HelpTypehtKeyword
  • 设置HelpKeywordhtml/edit1.html

When running the program you can focus the edit and press F1 to invoke the help. Under macOS the help key is Cmd-? (or Cmd+Shift+? depending on you keyboard layout). Note: Some window managers, widget set combinations do not pass F1 to the LCL.

INF (using fpGUI's DocView help viewer)

See the message and example project included in the Lazarus Forums. [1]

It shows a fully working example of an LCL application using fpGUI's DocView help viewer. It shows context sensitive help and general help.

例如:

  • Set focus to a specific control and press F1. It will show the help topic for that specific control.
  • Click the Help button and it will show the help topic for the dialog/form.
  • Select the "Help -> Show Help" menu item and it will show the general application help and display the first topic in the help file.

See also