Registering Help System Objects

From RAD Studio
Jump to: navigation, search

Go Up to Help System Interfaces


Help System objects that implement ICustomHelpViewer, IExtendedHelpViewer, ISpecialWinHelpViewer, and IHelpSelector must register with the Help Manager in order for the Help Manager to communicate with these Help System objects.

To register Help system objects with the Help Manager, you need to:

  • Register the Help viewer.
  • Register the Help Selector.

Registering Help viewers

The unit that contains the Help system object implementation must use System.HelpIntfs. An instance of the object must be declared in the var section of the implementing unit.

The initialization section of the implementing unit must assign the instance variable and pass it to the System.HelpIntfs.RegisterViewer function. RegisterViewer is a flat global function exported by the HelpIntfs unit, which takes as an argument an ICustomHelpViewer and returns a System.HelpIntfs.IHelpManager. The IHelpManager should be stored for future use.

For example, the VCL library provides the Vcl.HtmlHelpViewer unit that implements the Help viewer based on the HTMLHelp Windows help viewer. (See the MSDN library for information about the HTMLHelp function.) The initialization section of the Vcl.HtmlHelpViewer unit creates the Help viewer instance.

HelpViewer := THTMLHelpViewer.Create;

Here, the THTMLHelpViewer.Create constructor internally creates the HelpViewerIntf Help viewer object. The THTMLHelpViewer class is defined internally in the implementation section of the Vcl.HtmlHelpViewer unit. The THTMLHelpViewer class implements all HelpIntfs's interfaces required to the Help viewer. The created object is saved in the HelpViewer variable. The next line calls the global System.HelpIntfs.RegisterViewer function and passes to this function the created HelpViewerIntf Help Viewer object:

HelpIntfs.RegisterViewer(HelpViewerIntf, HelpViewer.FHelpManager);

RegisterViewer registers the created Help Viewer and returns the HelpViewer.FHelpManager Help manager. Later, the global System.HelpIntfs.GetHelpSystem function can be called from other units to access Help methods from the registered Help Viewer. In this way you can get access to implementations of all methods declared in the System.HelpIntfs.ICustomHelpViewer interface (and other interfaces of HelpIntfs) and that are implemented in the THTMLHelpViewer class.

The corresponding C++ code to register the discussed Help viewer can look like the following:

void InitServices()
{
    THelpImplementor GlobalClass;
    Global = dynamic_cast<ICustomHelpViewer*>(GlobalClass);
    Global->AddRef;
    HelpIntfs::RegisterViewer(Global, GlobalClass->Manager);
}
#pragma startup InitServices

Registering Help selectors

The unit that contains the object implementation must use VCL Forms. An instance of the object must be declared in the var section of the implementing unit.

The initialization section of the implementing unit must register the Help selector through the HelpSystem property of the global Application object:

Application.HelpSystem.AssignHelpSelector(myHelpSelectorInstance)
Application->HelpSystem->AssignHelpSelector(myHelpSelectorInstance)

This procedure does not return a value.

See Also