Sections management declarations
PlusMemo Help Send comments on this topic.
Sections management declarations

Glossary Item Box

 

Unit

PMSupport 

 

Declaration

type TStartStopKeyList = class(TObject)

      public

      Options: TWordOptions;

      constructor Create;

      procedure Clear;

      function AddStartStopKey(const StartKey, StopKey: string;

                               Options: TWordOptions;

                               Style  : TFontStyles;

                               ContextNumber   : Integer;

                               Cursor          : TCursor;

                               Backgnd, Foregnd: TColor; 

                               EndAtPar        : Boolean): Integer;

      procedure LoadFromIniStrings(IniStrings: TStrings);

      procedure SaveToIniStrings(IniStrings: TStrings);

      end;

 

Description

TStartStopKeyList is the type of object used for the automatic section formatting 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 your sections is not part of the text of a TPlusMemo.  It permits automatic highlighting of sections of text delimited by custom characters or expressions.  The typical usage of this object type is to initialize an instance of it with the start and stop key characteristics wanted for dynamic highlighting in a TPlusMemo and attach this instance to a TPlusMemo through its property StartStopKeys.

 

You assign values to a TStartStopKeyList with method AddStartStopKey.  Parameters StartKey and StopKey specify the strings that represent the start of a section and the stop of a section.  Whenever a start key is found in the text of a TPlusMemo or TDBPlusMemo, all the text comprised between the StartKey and StopKey (inclusive) will be formatted with the style and colors specified by parameters Style, Backgnd (the background color) and Foregnd (the text color).  If no stop key is found following a start key, the formatting will be applied up to the end of the text of the TPlusMemo.  

Parameter Options in method AddStartStopKey is used to specify whether a start and stop key is to be considered case sensitive or not (element woMatchCase).  It also controls whether it is delimiter aware or not (element woWholeWordsOnly).  The delimiters that a TPlusMemo take into account are those in its property Delimiters.

 

Parameter EndAtPar controls whether the section formatting ends at paragraph boundaries or can cross them.  This formatting will be removed whenever the text in the control changes so that the start key is no longer present.  ContextNumber is a number that will be passed to the OnContext event whenever the user clicks in the text between the start and stop key.  If set to zero, the OnContext event will not trigger.  Parameter Cursor indicates the shape of the mouse cursor when it moves over the text found to be inside the start and stop keys.  If crDefault is specified, no cursor change will occur.

 

If both Backgnd  and Foregnd are equal to zero, the colors used will be the default of the control, specified by the properties Color and Font.Color.  A value of clNone for either of these parameters also count as transparent as far as color is concerned.

 

Parameters StartKey and StopKey should not contain any carriage return character (#13);  the behavior of the TPlusMemo is not specified in this case.  Rather, to specify that the end of the section is the end of the paragraph where the start key is found, pass a null string in parameter StopKey and set EndAtPar to True.  It is not possible to do the same with StartKey: passing in a null string in this field may produce errors in the control.  So it is not possible to have that the start of every paragraph is the start of a section in this version of PlusMemo.

 

Whenever you want to change the content of a TStartStopKeyList, you need to empty it with method Clear and start over filling it with AddStartStopKey.

 

Method LoadFromIniStrings loads the keyword definitions from a TStrings object, where each item defines a start-stop key and is supposed to be of the form

start|stop=p1,p2,p3,p4,p5,p6,p7

where p1..p9 are integer values representing respectively the parameters Options, Style, ContextNumber, Cursor, Backgnd, Foregnd, EndAtParLoadFromIniStrings is typically called with a TStrings object loaded by calling ReadSection on a TIniFile.  Worth noting is that the pipe character ( | ) is used to separate the start from the stop definition on the left of the equal sign.

 

Similarly, SaveToIniStrings saves the 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.