Add Help to Your Application/ru: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | LCL поставляется со справочной системой и позволяет **создавать справку для ваших собственных приложений**. | |
| 2 | 2 | ||
| 3 | 3 | ## Быстрый старт | |
| 4 | 4 | ||
| 5 | 5 | Откройте пример приложения из examples/helphtml/. | |
| 6 | 6 | ||
| 7 | 7 | Этот проект показывает как использовать компоненты HTML-справки. Разместите их на форме Вашего проекта. Настройте пути и создайте несколько HTML-файлов. Затем задайте свойства HelpKeyword для элементов управления, описываемых в этих файлах. | |
| 8 | 8 | ||
| 9 | 9 | Посмотрите раздел **CHM** если хотите использовать CHM-файлы вместо HTML-файлов. | |
| 10 | 10 | ||
| 11 | 11 | Здесь есть очень хороший и простой пример использования CHM (chmdemo.zip): <http://forum.lazarus.freepascal.org/index.php/topic,38487.msg261731.html#msg261731> | |
| 12 | 12 | ||
| 13 | 13 | ## Основы справочной системы в LCL | |
| 14 | 14 | ||
| 15 | 15 | Справочная система, создаваемая с помощью LCL, состоит из двух частей: "базы данных справочной системы" (набора HTML/XML/CHM-файлов) и средства просмотра справочной системы. База данных справки содержит сопоставление ключевых слов (ID, node, message, pascal, ...) со страницей справки (или web-сайтом, или...). Средство просмотра справки вызывается базой данных справки для отображения справки пользователю. | |
| 16 | 16 | ||
| 17 | 17 | - [[THelpDatabase]] управляет контентом. It can be a collection of HTML pages or fpdoc XML files or a CHM file or a database or whatever. | |
| 18 | 18 | - [[THelpViewer]] is a component that shows help content. For example a viewer for the mime type text/html can start a web browser. | |
| 19 | 19 | ||
| 20 | 20 | When 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. | |
| 21 | 21 | ||
| 22 | 22 | ## CHM | |
| 23 | 23 | ||
| 24 | 24 | Context-sensitive CHM application help can be used from Lazarus 1.0 and later. | |
| 25 | 25 | ||
| 26 | 26 | 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/. | |
| 27 | 27 | ||
| 28 | 28 | 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 You can use a [[TCHMHelpDatabase]] control like the [[THTMLHelpDatabase]] control described below. | |
| 29 | 29 | ||
| 30 | 30 | 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). | |
| 31 | 31 | ||
| 32 | 32 | ### Using LHelp | |
| 33 | 33 | ||
| 34 | 34 | - Put a **TLHelpConnector** on your form. | |
| 35 | 35 | - Set **LHelpPath** with the name and location of the LHelp executable (this can be absolute, or relative to the application directory) | |
| 36 | 36 | - Set **AutoRegister** to true | |
| 37 | 37 | ||
| 38 | 38 | ``` pascal | |
| 39 | 39 | // Example with both chm file and LHelp.exe in Application folder. | |
| 40 | 40 | Procedure TForm1.FormCreate(Sender: TObject); | |
| 41 | 41 | Begin | |
| 42 | 42 | If FileExists(ChangeFileExt(Application.ExeName, '.chm')) Then | |
| 43 | 43 | Begin | |
| 44 | 44 | CHMHelpDatabase1.Filename := ChangeFileExt(Application.ExeName, '.chm'); | |
| 45 | 45 | CHMHelpDatabase1.KeywordPrefix := 'test'; | |
| 46 | 46 | CHMHelpDatabase1.AutoRegister:=True; | |
| 47 | 47 | ||
| 48 | 48 | LHelpConnector1.LHelpPath := IncludeTrailingBackSlash(ExtractFileDir(Application.ExeName)) + 'lhelp.exe'; | |
| 49 | 49 | LHelpConnector1.AutoRegister:=True; | |
| 50 | 50 | end | |
| 51 | 51 | Else | |
| 52 | 52 | mnuHelpMain.Enabled := False; | |
| 53 | 53 | End; | |
| 54 | 54 | ||
| 55 | 55 | Procedure TForm1.Button1Click(Sender: TObject); | |
| 56 | 56 | Begin | |
| 57 | 57 | If mnuHelpMain.Enabled Then | |
| 58 | 58 | ShowHelpOrErrorForKeyword('','test/Main.html'); | |
| 59 | 59 | //ShowTableOfContents; (Not implemented for TCHMHelpDatabase) | |
| 60 | 60 | End; | |
| 61 | 61 | ``` | |
| 62 | 62 | ||
| 63 | 63 | ## HTML | |
| 64 | 64 | ||
| 65 | 65 | 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. | |
| 66 | 66 | ||
| 67 | 67 | ### Setup HTML help for your application | |
| 68 | 68 | ||
| 69 | 69 | <img src="LazHtmlHelp.jpg" title="Lazarus help items" width="500" alt="Lazarus help items" /> Adding HTML help to your application is easy: | |
| 70 | 70 | ||
| 71 | 71 | - Put a **THTMLHelpDatabase** on a form. | |
| 72 | 72 | - Set **AutoRegister** to true. | |
| 73 | 73 | - Set **KeywordPrefix** to **html/**. It means all keywords must start with the string *html/*. | |
| 74 | 74 | - 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/>*. | |
| 75 | 75 | ||
| 76 | 76 | - Put a **THTMLBrowserHelpViewer** on the form. This component can start the user's default browser. | |
| 77 | 77 | - Set **AutoRegister** to true. | |
| 78 | 78 | ||
| 79 | 79 | ### Creating a help entry | |
| 80 | 80 | ||
| 81 | 81 | - 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>* | |
| 82 | 82 | - Put a TEdit on a form | |
| 83 | 83 | - Set **HelpType** to *htKeyword* | |
| 84 | 84 | - Set **HelpKeyword** to *html/edit1.html* | |
| 85 | 85 | ||
| 86 | - | ||
| 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). | |
| 87 | 87 | ||
| 88 | - | ||
| 88 | + | Note: Some window managers, widget set combinations do not pass `F1` to the LCL. | |
| 89 | 89 | ||
| 90 | 90 | ## INF (using fpGUI's DocView help viewer) | |
| 91 | 91 | ||
| 92 | 92 | See the message and example project included in the Lazarus Forums. [1](http://forum.lazarus.freepascal.org/index.php/topic,27864.msg173887.html#msg173887) | |
| 93 | 93 | ||
| 94 | 94 | It 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. | |
| 95 | 95 | ||
| 96 | 96 | For example: | |
| 97 | 97 | ||
| 98 | - | ||
| 98 | + | - Set focus to a specific control and press `F1`. It will show the help topic for that specific control. | |
| 99 | 99 | - Click the Help button and it will show the help topic for the dialog/form. | |
| 100 | 100 | - Select the "Help -\> Show Help" menu item and it will show the general application help and display the first topic in the help file. | |
| 101 | 101 | ||
| 102 | 102 | ## See also | |
| 103 | 103 | ||
| 104 | 104 | - [[Add an Apple Help Book to your macOS app]] | |
| 105 | 105 | ||
| 106 | 106 | --- | |
| 107 | 107 | *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).* | |
| 108 | 108 | Category: CHM | |
| 109 | 109 | Category: Help and Docs | |
| 110 | 110 | Category: Tutorials |
