Sign in Join
Wiki copytemporary

Add Help to Your Application: what changed

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

OldNewLine
11The LCL comes with a help system, and allows you to **create help for your own applications**.
22
33## Quick Start
44
55Open the example in examples/helphtml/.
66
77This project demonstrates how to use the HTML help components. Just drop them on a form of your project. Setup the paths and create some HTML pages. Then give each control of your application a HelpKeyword.
88
99See the CHM help section if you want to use CHM help files instead of HTML help files.
1010
1111There is a very nice simple demo (chmdemo.zip) here: <http://forum.lazarus.freepascal.org/index.php/topic,38487.msg261731.html#msg261731>
1212
1313## Help Basics
1414
1515The LCL help mainly consists of two parts: Help databases and help viewers. A Help Database contains the mapping from the keywords (ID, node, message, pascal, ...) to the help page (or help web site or...). The Help Viewer is invoked by the Help Database to show the help to the user.
1616
1717- 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.
1818- A [[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- Drop a **`TCHMHelpDatabase`** on your form.
3535- Set its **`FileName`** property to the path to the chm file, and set **`AutoRegister`** to `true`.
3636- In **`KeywordPrefix`** specify the path to the html files contained in the chm file as seen from the chm root. Example: If the html help files during chm creation are in the subfolder *html* the `KeywordPrefix` is `html` (without trailing path delimiter!).
3737- Put a **`TLHelpConnector`** on your form.
3838- Set **`LHelpPath`** to the name and location of the LHelp executable (this can be absolute, or relative to the application directory)
3939- Set **`AutoRegister`** to `true`.
4040
4141``` pascal
4242// Example with both chm file and LHelp.exe in Application folder.
4343procedure TForm1.FormCreate(Sender: TObject);
4444begin
4545 if FileExists(ChangeFileExt(Application.ExeName, '.chm')) then
4646 begin
4747 CHMHelpDatabase1.Filename := ChangeFileExt(Application.ExeName, '.chm');
4848 CHMHelpDatabase1.KeywordPrefix := 'html';
4949 CHMHelpDatabase1.AutoRegister:=True;
5050
5151 LHelpConnector1.LHelpPath := IncludeTrailingBackSlash(ExtractFileDir(Application.ExeName)) + 'lhelp.exe';
5252 LHelpConnector1.AutoRegister:=True;
5353 end
5454 else
5555 mnuHelpMain.Enabled := False;
5656end;
5757
5858procedure TForm1.Button1Click(Sender: TObject);
5959begin
6060 if mnuHelpMain.Enabled then
6161 ShowHelpOrErrorForKeyword('', 'html/main.html');
6262 //ShowTableOfContents; (Not implemented for TCHMHelpDatabase)
6363end;
6464```
6565
6666When LHelp is invoked during execution of your project it is started by *Inter-Process Communication* (IPC) in a separate process which normally does not terminate when you application is closed. If you want to close LHelp with your application you should write an `OnDestroy` event handler to send an `mrClose` command to LHelp via IPC:
6767
6868``` Pascal
6969uses
7070 LHelpControl; // for "mrClose"
7171
7272procedure TForm1.FormDestroy(Sender: TObject);
7373begin
7474 if (LHelpConnector1.Connection <> nil) and LHelpConnector1.Connection.ServerRunning then
7575 LHelpConnector1.Connection.RunMiscCommand(LHelpControl.mrClose);
7676end;
7777```
7878
7979## HTML
8080
8181The 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.
8282
8383### Setup HTML help for your application
8484
85-<img src="LazHtmlHelp.jpg" title="Lazarus help items" width="500" alt="Lazarus help items" /> Adding HTML help to your application is easy:
85+![Lazarus help items](/wiki-images/7/7e/LazHtmlHelp.jpg) Adding HTML help to your application is easy:
8686
8787- Put a **THTMLHelpDatabase** on a form.
8888- Set **AutoRegister** to true.
8989- Set **KeywordPrefix** to **html/**. It means all keywords must start with the string *html/*.
9090- Set **BaseURL** to **<file://yourhelp/>**. This will search for HTML files in the sub folder 'yourhelp' relative to the application directory. You can specify an absolute path to the directory where HTML files are stored. For UNIX-like platforms, use an URL like *<file:///usr/lib/yourhelp/>* for local access or an URL like *<http://www.yoursite.com/>* for web access. For the Windows platform, use an URL like *<file://c:/temp/html/>* or *[file://c:\temp\html](file://c:\temp\html)*.
9191- Put a **THTMLBrowserHelpViewer** on the form. This component can start the user's default browser.
9292- Set **AutoRegister** to true.
9393
9494### Creating a help entry
9595
9696- 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>*
9797- Put a TEdit on a form
9898- Set **HelpType** to *htKeyword*
9999- Set **HelpKeyword** to *html/edit1.html*
100100
101101When 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).
102102
103103Note: Some window managers, widget set combinations do not pass `F1` to the LCL.
104104
105105## INF (using fpGUI's DocView help viewer)
106106
107107See the message and example project included in the Lazarus Forums. [1](http://forum.lazarus.freepascal.org/index.php/topic,27864.msg173887.html#msg173887)
108108
109109It 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.
110110
111111For example:
112112
113113- Set focus to a specific control and press `F1`. It will show the help topic for that specific control.
114114- Click the Help button and it will show the help topic for the dialog/form.
115115- Select the "Help -\> Show Help" menu item and it will show the general application help and display the first topic in the help file.
116116
117117## See also
118118
119119- [[Add an Apple Help Book to your macOS app]]
120120
121121---
122122*From the Free Pascal wiki, page "Add Help to Your Application", as it stood on 2024-03-10 after a change by Dsiders, 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).*
123123Category: CHM
124124Category: Help and Docs
125125Category: Tutorials

Back to history