Unit
Declaration
type TWordOption = (woMatchCase, woWholeWordsOnly, woFirstParWord, woFirstNonBlank, woStartPar);
TWordOptions = set of TWordOption;
TKeywordInfo = packed record
Options : TWordOptions;
Style : TFontStyles;
ContextNumber: Integer;
Cursor : TCursor;
Backgnd, Foregnd: Tcolor
end;
TKeywordList = class(TStringList)
public
function AddKeyword(const KeyWord : string;
Options : TWordOptions;
Style : TFontStyles;
ContextNumber : Integer;
Cursor : TCursor;
Backgnd, Foregnd: TColor): Integer;
property KeyInfos[i: Integer]: TKeywordInfo;
{ read and write access }
procedure LoadFromIniStrings(IniStrings: TStrings);
procedure SaveToIniStrings(IniStrings: TStrings);
end;
Description
These are the types used for the automatic keyword highlighting functionality of TPlusMemo or TDBPlusMemo. This functionality is one of the three ways of achieving dynamic styling, meaning that the formatting information used to highlight keywords is not considered part of the text of a TPlusMemo or TDBPlusMemo. In a typical situation, the keywords that you want highlighted in a TPlusMemo are put in a TKeywordList . This TKeywordList is then attached to a TPlusMemo through its Keywords property.
TKeywordList is an object derived from TStrings that contains a list of keywords with their options and style. Property KeyInfos can be used to set or retrieve the keyword information of each keyword. Function AddKeyword can be used to enter a new keyword in a list along with its options and style. The return value is the index of the keyword that has been added. All other public properties and methods of TStrings are available and effective, particularly Count, Strings, Insert, Clear. Before adding items to the list, it is advisable to call BeginUpdate to avoid a lot of memory reallocations. The list modification should then be followed by a call to EndUpdate.
Keyword options
TWordOptions is the set of options that each keyword can have. The value woMatchCase specifies whether the keyword is to be considered case sensitive or not. The value woWholeWordsOnly affects the algorithm for locating keywords in the text. If present, only keywords surrounded by delimiters will be highlighted. If not, all occurrences of the keyword will be considered good candidates. The delimiters that the keyword highlighting engine will take into account are those of property Delimiters of a TPlusMemo.
woFirstParWord, woFirstNonBlank and woStartPar control the positional dependency of the keyword relative to the start of its paragraph. These members are effective only in TExtHighlighter components and descendants. If woFirstParWord is specified, the keyword will be highlighted only if it is the first word of a paragraph. If woFirstNonBlank is set, only spaces and tabs can precede the keyword for it to be highlighted. This member takes precedence over woFirstParWord. Similarly, woStartPar is used to highlight a keyword only if it is located at the start of a paragraph. This option overrules the former ones.
Keyword information
TKeywordInfo is a structure that contains the word options and the style to apply to a keyword. Parameter Style is of type TFontStyles and can specify ordinary font styles and/or extended ones (fsHighlight, fsAltFont) through typecasting. Cursor member specifies what you want as cursor when the mouse is over the keyword. Specify crDefault if you want no mouse cursor change. ContextNumber is the value that will be passed to the OnContext event when the user clicks on this keyword with the mouse. It should not be set to zero in this version of PlusMemo. Doing so will result in the keyword not being highlighted. Parameters Backgnd and Foregnd specify respectively the background and text color that you want to apply for a keyword. If both of them are zero, the colors will be the default ones, specified by the properties Color and Font.Color of the control. A value of clNone also makes the color transparent, i.e. using the default one.
Loading/saving keyword definitions
Method LoadFromIniStrings loads the keyword definitions from a TStrings object, where each item defines a keyword and is supposed to be of the form
keyword=p1,p2,p3,p4,p5,p6
where p1..p6 are integer values representing respectively the parameters Options, Style, ContextNumber, Cursor, Backgnd, and Foregnd. LoadFromIniStrings is typically called with a TStrings object loaded by calling ReadSection on a TIniFile.
Similarly, SaveToIniStrings saves the keyword definitions into a TStrings object in the same ini file format. The resulting TStrings object is then typically saved to an ini file by calling WriteString on a TIniFile for each item in it.