19th Chapter-delphi Custom Parts Development (iii) (3)

Source: Internet
Author: User
Tags constructor requires

Compiled Help files and keyword files should be in the same directory as the library unit.

① Build Help file

You can use any tool to create a Windows Help file. Delphi's multi-file search engine can contain elements of any number of help files. In addition to the compiled Help file, you should have a rich text source file in order to generate a keyword file.

To enable help for a custom part to work with other parts in the library, follow these conventions:

Each part has the help of one page

The part help page should give a brief description of the part's purpose, and then list the properties, events, and methods that are available to end users. The application developer accesses the page by selecting a part on the form and pressing F1.

The part help page should have a "k" Footnote for keyword search, and a footnote containing the part name. For example, TMemo's keyword footnote reads "TMemo Component"

Parts added and modified for each attribute, event and method should have a page help

The help page for a property, event, or method should indicate which part the item is used for, display the declaration syntax, and describe how it is used.

The help page for a property, event, or method should have a "K" footnote for the keyword search that contains the name and type of the item. For example, the keyword footnote to the top of the property is "top."

Each page of the Help file also requires special footnotes for multiple file index searches.

② Add Special Footnotes

Delphi requires special search keywords to distinguish between help pages and other items for a part. You should provide a standard keyword search term for each item. But you also need a special footnote for Delphi.

To add a keyword to a search from the Object Inspector window or the Code Editor F1, you have to add a "B" footnote to the Help file Assistance page.

"B" footnotes are very much like the "K" footnotes used for standard WinHelp keyword searches, but they are used only for Delphi search engines. The following table lists how to create a "B" footnote for each part of the help page:

Table 19.7 Parts help page Search footnote

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Help page type "B" footnote content example

──────────────────────────────────

Main part Page ' Class_ ' + part type name CLASS_TMEMD

General property or Event page ' Prop_ ' + property name Prop_wordwrap

' Event_ ' + event name Event_onchange

Part-specific attribute ' prop_ ' + part type name Prop_tmemowordwrap

or event page + property name

' Event_ ' + part type name Event_tmemoonchange

+ Event Name

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

It is important to distinguish between general help pages and part-specific help pages. The general help page applies to specific properties and events on all parts. For example, the left property is an identity in all parts. Therefore, it searches with a string prop-left. The Borde-style relies on the part they belong to, so the BorderStyle property has its own help page. For example, Tedit has a help page with the BorderStyle property, and the search string is Prop_teditborderstyle.

③ Create a keyword file

The Help file is built and compiled, and the footnotes are added, and independent keyword files are generated so that Delphi can insert them into the index of the subject search.

The way to create a keyword file from the Help resource file Rich text is as follows:

At the DOS prompt, go to the directory that contains the RTF file

Run keyword file generation program--kwgen. EXE, followed by Help engineering files, such as Kwgen SPECIAL. HPJ. When the Kwgen is finished, it has the same keyword file as the Help engineering file, but. KWF is the extended name

Put the keyword file in the same directory as the compiled library unit and help file

When you install the widget on the component palette, you want the keyword to be inserted into the Delphi Help system Search index.

④ Insert Help Index

After you create a keyword file with a custom part, insert the keyword into the Help Index of Delphi.

The way to insert a keyword file into the Detphi Help index is as follows:

Put the keyword file in the same directory as the compiled library unit and the Heph file

Running the Helpinst program

After the Helpinst run, Delphi's Help Index file (. HDX) contains the keywords for the custom part help page.

⑶ Store and Mount Properties

Delphi stores the form and the parts it owns in the form file (. DFM), the DFM file uses a binary representation of the form's properties and its parts. When Delphi users add custom parts to the form, the custom parts should have the ability to store their properties. Similarly, components must be able to recover them from the DFM file when they are transferred to Delphi or the application.

Most of the time, there is no need to do anything to make parts read and write DFM files. Both storage and loading are part of the behavior of inherited ancestor parts. In some cases, however, you may want to change the way parts are stored and loaded for initialization. Therefore, the following mechanisms should be understood:

Storage and loading mechanisms

Describe default values

Decide what to store

Initialization after Mount

① Storage and loading mechanism

When the application developer designs the form, Delphi stores the description of the form in the DFM file. When the user runs the program, it reads these descriptions.

A description of a form contains a series of form properties and a similar description of the parts in the form. Each part, including the form itself, is responsible for storing and loading its own description.

By default, when stored, the part writes the values of all public and published properties different from the default values in the order in which they are declared. When loaded, the part constructs itself first and sets all the properties to the default values, and then reads the stored, Non-default property values.

This default mechanism satisfies the needs of most parts without the need for any work by the part creator. However, there are several ways to define your own storage and loading processes to fit your custom parts.

② describes the default value.

The Delphi part stores only those attributes whose property values are different from the default values. If you do not describe, Delphi assumes that the attribute has no default value, which means that the part always stores the attribute.

The value of an attribute is not set by the constructor, it is assumed to be a zero value. To describe a default value, add the default directive and the new default value after the property declaration.

You can also describe the default value when you re declaring an attribute. In fact, one reason to declare a property is to specify a different default value. Only the default value is described, the property is not automatically assigned to the object when it is created, and the desired value is assigned to the part's create method.

The following code demonstrates the process of describing a default value using the Align property.

Type

Tstatusbar=class (Tpanel)

Public

Constructor Create (aowner:tcomponent); Override {Overwrite to set new value}

Published

Property Align default Albottom; {re-declaring defaults}

End

Constructor Tstatusbar.create (aowner:tcomponent);

Begin

Inherited Create (Aowner); {Perform an inherited initialization process}

Align: = Albottom; {Assign a new default value for align}

End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.