HTMLHELP components Implement HTML help in Delphi applications

zhaozj2021-02-17  50

A friendly app for user-friendly is a perfect online help. . HLP format helps files have been widely used as the standard Help file format of the Windows platform, and is also well supported by many applications, such as Delphi, etc. As Microsoft began supporting .chm (compiled HTML Help file) format from Windows98, this interface is more friendly to help file formats have been more and more widely used.

Currently, Delphi is not like supporting. HLP helps directly support the context help. However, through a third party's HTMLHELP component, HTML help in the Delphi application becomes equally simple. This article describes the HTMLHELP components and their applications in the development of Delphi applications.

Download HTMLHELP components

The HTMLHELP component is released under the MPL license, which is completely free and supplies source code for download. The download URL is: http://www.serveisgirona.com/delphi/htmlh/index.htm. The current version of this component is version 1.0.

2. Install HTMLHELP components

Open the downloaded compressed package HTMLPAK.ZIP (no sample program) or htmlall.zip (including sample programs), extract it into a directory, such as / delphi5 / lib / htmlhlp. Open the HHPACK.DPK file in this directory in Delphi and pop up the package manager. Click on the Options button of the Pack Manager toolbar to set the Unit Output Directory option to $ (Delphi) / lib. Click the Compile button on the toolbar to compile the component package, then click the Install button to install it. After completing the correct installation, a component panel named HTML Help is added on the component bar of Delphi, which only HTMLHELP is only one component.

3. Attributes and methods of htmlhelp components

HTMLHELP only provides several simple and practical properties and methods, which makes them a detailed introduction.

3.1HTMLHELP properties

HTMLHELP provides three attributes shown in Table 1: Table 1 Attribute Attribute Attribute Attribute Attribute Name of the HTMLHELP component Name The name of the CHMFileStringPublished help file. You must set this property to the absolute path and file name of the help file, otherwise you can change the corresponding help file when you change the current directory during the program run. WINDEFSTRINGPUBLISHED You may have a custom window definition when you create an HTML Help file. You can specify the window definition you want to use here. DefautfileBooleanpublished You can set whether you use the default help file name. When this property is set to FALSE, the component will use the help file specified by chmfile. If you set this property to true, the component will automatically set the chmfile property to an empty string, and check if you set Application.HelpFile when initialization. If Application.helpFile is set (set on the Project Options Application tab, you can check and expand the HelpFile property value to get the full path and file name of the help file; If you don't set Application.helpfile, the component will try to set the help file to the same name in the directory where the application is located, but the extension of the file named .chm. It should be noted that in the 1.0 version of the component, there are some issues in the implementation of the defaultfile attribute, and automatic search function is not completed in the help documentation of the component. You either set the defaultfile property to false and set the absolute path and file name of the help file in the chmfile property; or set the defaultfile property to true and specify the help file name (no path information) or in Application.HelpFile The absolute path and file name of the help file. The author has modified the component and sent a letter to the component author, and believes that the author will launch a revised version soon. 3.2 Methods of HTMLHELP components HTMLHELP provides 5 methods for controlling display-related help windows and help topics. Table 2 Method for defining methods for HTMLHELP components Description Function HelpContext (ContextID: DWORD): Integer; Displays the help topic associated with contextid. If the HelpContext property of the Delphi component object on a form is set, the method will call the method after the F1 key is pressed, and the HelpContext property value will be called to ContextID. Function Helptopic (Topic: String): Integer; Displays help information with topic. Function ShowIndex: Integer; Display the index page on the navigation panel of the help window. Function ShowTableOfContents: Integer; Displays the directory list on the navigation panel of the help window. Function ShowSearch: Integer; Displays the search page on the navigation panel of the help window. 4. It is very convenient to use the HTMLHELP components using the HTMLHELP component. The method of use of the assembly is specifically described below with a simple example. The sample program is a simple open file dialog as shown in Figure 1. The application name is HTMLHELPDEMO.EXE. Figure 1 Open the file dialog

The steps to implement HTML HTML help in the Delphi application design are as follows: (1) Creating a help file in the CHM format. You can create a CHM help file using Microsoft's HTML Help Workshop (download address http://msdn.microsoft.com/library/tools/htmlhelp/wkshp/htmlhelp.exe), you can also use third parties to help file creation tools. For example, Help & Mannual, Dothelp and other software are created. For details, please refer to the user manual for the relevant software, this is not discussed here. However, you must pay attention to the use of context help in the application, you must specify a corresponding contextID for the relevant topic. In the sample program, a help file called HTMLHELPDEMO.CHM is used. This file contains four topics, which open the dialog, file name edit box, browsing buttons, and file type checkbox, the corresponding contextId is 1000, 1001, 1002, and 1003. (2) Place an HTMLHELP component on the main form of the application from the HTML HELP component panel and set its property value. In this example, because the open dialog is the main form, the component is placed on it. Typically, it can be used directly to use its default attribute value, which is set to true, and then use the application with the application in the same directory, the file name is the same and the help file named .CHM, or in the Application.HelpFile property Set the help file name you want to use. Of course, you can also specify the absolute path and file name of the help file you want to use in the chmfile property of the component, but do not recommend this because it is usually not convenient to install the help file to a fixed directory. In this case, all of the default values ​​of the HTMLHELP component are all used, and the HelpFile property of the Application object is set. (3) Setting the HelpContext attribute value to display the component objects that need to display the context. For example, in Figure 2, set the HelpContext of the file name edit box component to 1001. Figure 2 Set the HelpContext attribute of the component object

⑷ In other event responses that need to display help information, call the corresponding method of the HTMLHELP component. In this example, when you click the Help button, you need to display help information about the dialog. The event response process is as follows: procedure topendlg.helpbtnclick (sender: TOBJECT); begin htmlhelp1.helpContext (1000); END; Complete other parts of the application design and generate an application. In this example, an application called HTMLHELPDEMO.EXE is generated, and the help file HTMLHELPDEMO.CHM is copied to the same directory. Run the program, in the case where the file name edit box gets the focus, press the F1 button to pop up the help information as shown in Figure 3.

Figure 3 File Name Editing Context Help

When you click on the Help button, the help window is shown in Figure 4 on the open dialog.

Figure 4 Help the dialog

5. End language Use the HTMLHELP component to easily implement HTML help in the Delphi application. Although this type of help can be implemented by directly calling other methods such as HTMLHELP API, the use of this component can undoubtedly reduce programming workload.

转载请注明原文地址:https://www.9cbs.com/read-28383.html

New Post(0)