Sign in Join
Wiki copytemporary

Add Help to Your Application/ru: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11LCL поставляется со справочной системой и позволяет **создавать справку для ваших собственных приложений**.
22
33## Быстрый старт
44
55Откройте пример приложения из examples/helphtml/.
66
77Этот проект показывает как использовать компоненты HTML-справки. Разместите их на форме Вашего проекта. Настройте пути и создайте несколько HTML-файлов. Затем задайте свойства HelpKeyword для элементов управления, описываемых в этих файлах.
88
99Посмотрите раздел **CHM** если хотите использовать CHM-файлы вместо HTML-файлов.
1010
1111Здесь есть очень хороший и простой пример использования CHM (chmdemo.zip): <http://forum.lazarus.freepascal.org/index.php/topic,38487.msg261731.html#msg261731>
1212
1313## Основы справочной системы в LCL
1414
1515Справочная система, создаваемая с помощью LCL, состоит из двух частей: "базы данных справочной системы" (набора HTML/XML/CHM-файлов) и средства просмотра справочной системы. База данных справки содержит сопоставление ключевых слов (ID, node, message, pascal, ...) со страницей справки (или web-сайтом, или...). Средство просмотра справки вызывается базой данных справки для отображения справки пользователю.
1616
1717- [[THelpDatabase]] управляет контентом. It can be a collection of HTML pages or fpdoc XML files or a CHM file or a database or whatever.
1818- [[THelpViewer]] is a component that shows help content. For example a viewer for the mime type text/html can start a web browser.
1919
2020When help is requested, 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.
2121
2222## CHM
2323
2424Context-sensitive CHM application help can be used from Lazarus 1.0 and later.
2525
2626A 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/.
2727
2828You 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 You can use a [[TCHMHelpDatabase]] control like the [[THTMLHelpDatabase]] control described below.
2929
3030The 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).
3131
3232### Using LHelp
3333
3434- Put a **TLHelpConnector** on your form.
3535- Set **LHelpPath** with the name and location of the LHelp executable (this can be absolute, or relative to the application directory)
3636- Set **AutoRegister** to true
3737
3838``` pascal
3939// Example with both chm file and LHelp.exe in Application folder.
4040Procedure TForm1.FormCreate(Sender: TObject);
4141Begin
4242 If FileExists(ChangeFileExt(Application.ExeName, '.chm')) Then
4343 Begin
4444 CHMHelpDatabase1.Filename := ChangeFileExt(Application.ExeName, '.chm');
4545 CHMHelpDatabase1.KeywordPrefix := 'test';
4646 CHMHelpDatabase1.AutoRegister:=True;
4747
4848 LHelpConnector1.LHelpPath := IncludeTrailingBackSlash(ExtractFileDir(Application.ExeName)) + 'lhelp.exe';
4949 LHelpConnector1.AutoRegister:=True;
5050 end
5151 Else
5252 mnuHelpMain.Enabled := False;
5353End;
5454
5555Procedure TForm1.Button1Click(Sender: TObject);
5656Begin
5757 If mnuHelpMain.Enabled Then
5858 ShowHelpOrErrorForKeyword('','test/Main.html');
5959 //ShowTableOfContents; (Not implemented for TCHMHelpDatabase)
6060End;
6161```
6262
6363## HTML
6464
6565The 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.
6666
6767### Setup HTML help for your application
6868
6969<img src="LazHtmlHelp.jpg" title="Lazarus help items" width="500" alt="Lazarus help items" /> Adding HTML help to your application is easy:
7070
7171- Put a **THTMLHelpDatabase** on a form.
7272- Set **AutoRegister** to true.
7373- Set **KeywordPrefix** to **html/**. It means all keywords must start with the string *html/*.
7474- 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/>*.
7575
7676- Put a **THTMLBrowserHelpViewer** on the form. This component can start the user's default browser.
7777- Set **AutoRegister** to true.
7878
7979### Creating a help entry
8080
8181- Now create the subfolder *yourhelp* and create an HTML page *yourhelp/edit1.html*. In case of a website, the help page should be accessible as *<http://www.yoursite.com/edit1.html>*
8282- Put a TEdit on a form
8383- Set **HelpType** to *htKeyword*
8484- Set **HelpKeyword** to *html/edit1.html*
8585
86-When running the program you can focus the edit control and press <span class="kbd">F1</span> to invoke the help. Under macOS the help key sequence is <span class="kbd">Cmd-?</span> (or <span class="kbd">Cmd+Shift+?</span> depending on your keyboard layout).
86+When running the program you can focus the edit control and press `F1` to invoke the help. Under macOS the help key sequence is `Cmd-?` (or `Cmd+Shift+?` depending on your keyboard layout).
8787
88-Note: Some window managers, widget set combinations do not pass <span class="kbd">F1</span> to the LCL.
88+Note: Some window managers, widget set combinations do not pass `F1` to the LCL.
8989
9090## INF (using fpGUI's DocView help viewer)
9191
9292See the message and example project included in the Lazarus Forums. [1](http://forum.lazarus.freepascal.org/index.php/topic,27864.msg173887.html#msg173887)
9393
9494It shows a fully working example of an LCL application using [[fpGUI]]'s [DocView help viewer](http://fpgui.sourceforge.net/screenshots_apps.shtml). It shows context sensitive help and general help.
9595
9696For example:
9797
98-- Set focus to a specific control and press <span class="kbd">F1</span>. It will show the help topic for that specific control.
98+- Set focus to a specific control and press `F1`. It will show the help topic for that specific control.
9999- Click the Help button and it will show the help topic for the dialog/form.
100100- Select the "Help -\> Show Help" menu item and it will show the general application help and display the first topic in the help file.
101101
102102## See also
103103
104104- [[Add an Apple Help Book to your macOS app]]
105105
106106---
107107*From the Free Pascal wiki, page "Add Help to Your Application/ru", as it stood on 2021-09-13 after a change by DmitrySokolov, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
108108Category: CHM
109109Category: Help and Docs
110110Category: Tutorials

Back to history