How to Connect HTML Help with your Delphi Application

If you are a Delphi developer, you can easily integrate an HTML Help (CHM) system with your application since modern Delphi versions include built-in support for this help format. Below you will find a description of how to work with HTML Help from your Delphi programs. Also, we have a sample Delphi project which demonstrates everything in action.

Linking HTML Help (CHM) Files

You should add the "HTMLHelpViewer" unit to the "Uses" clause in the main form of your application. Then set the full path to your CHM file to Application.HelpFile property. To do so, you can add the following line to the main form's "On Create" event handler:

Application.HelpFile := ExtractFilePath(Application.ExeName) + 'HelpFile.chm';

where "HelpFile.chm" is the actual name of your HTML Help file, located in the same directory as your application's executable file.

Using HTML Help from Code

When you need to display your help file or a specific help topic, or perform others actions, you can use the following calls:

  1. Displaying a help topic
    Application.HelpContext(IDH_TOPIC);

    where IDH_TOPIC is the ContextId value of the topic to display.

  2. Displaying the Table of Contents tab
    HtmlHelp(0, Application.HelpFile, HH_DISPLAY_TOC, 0);

  3. Displaying the Index tab
    HtmlHelp(0, Application.HelpFile, HH_DISPLAY_INDEX, DWORD(PWideChar('Test')));

  4. Displaying the Search tab
    var
      Query: THH_Fts_QueryW;
    with Query do
    begin
      cbStruct:= SizeOf(THH_Fts_QueryW);
      fUniCodeStrings:= True;
      pszSearchQuery:= '';
      iProximity:= 0;
      fStemmedSearch:= True;
      fTitleOnly:= False;
      fExecute:= True;
      pszWindow:= nil;
    end;
    HtmlHelp(0, Application.HelpFile, HH_DISPLAY_SEARCH, DWORD(@Query));


  5. Performing Keyword Lookup
    Application.HelpKeyword('Test');

Providing Help for Controls

You can link specific help topics with any controls located on the form. In this case a control will automatically display the corresponding help topic when the user focuses it and presses F1. Also, you can add the standard [?] button to the caption area of the form: using the Object Inspector, set the form's BorderStyle property as bsDialog and biHelp member of the BorderIcons property to True. Then set the controls' HelpContext properties that should correspond to the topic ContextId values as defined in your help project.

Sample Delphi Project

You can download a Delphi project that implements the above examples. Click here to start downloading.


Add to Reddit Add to Digg Add to del.icio.us Add to StumbleUpon Add to Facebook Add to BlinkList Add to Furl Add to Spurl Add to Fark Add to Google Add to YahooMyWeb Add to Twitter

Learn More About HelpSmith