TXRichEdt 1.0

1. Overview

'TXRichEdt' is a descendent of 'TRichEdit' which adds the ability of syntax
highlighting to it's predecessor. Using the new properties 'KeyWords1' and
'KeyWords2' you define the keywords to be highlighted. Once you set the property
'Syntaxhervorhebung' to true, these keywords are displayed using the fonts
'KeyFont1' and 'KeyFont2'.

The advantage of this component is to be very simple; the main drawback is that
loading a large file with many keywords can take a while. This is due to the
internal implementation of the process of syntax highlighting; see section 4.

There are some more properties and methods that have been added; these are described
in the following sections.


2. New properties and events

The following properties and events have been added to TRichEdit and are accessible
via the object inspector:


property Letters: string

This property defines the letters that make up the keywords. The letters 'a'..'z'
and 'A'..'Z' are always considered as letters - you only have to add "special"
characters: In case your keywords contain digits, you have to set letters :=
'0123456789'.


property KeyWords1: TKeyWord
property KeyWords2: TKeyWord

As discussed in section 1, these properties define the keywords to be highlighted.
'TKeyWord' is a descended of 'TStringList'. You can either define the keywords via
the object inspector or from your program.

IMPORTANT: The strings within these lists have to be sorted in the order given by
'CompareStr'; you can use the 'Sort' method of 'TKeyWord' to put the keywords in the
appropriate order.


property KeyFont1: TFont
property KeyFont2: TFont

As discussed in section 1, these are the fonts used to display the given keywords in
case 'Syntaxhervorhebung' is true. See also 'UseFullFont'.


property UseFullFont: Boolean

Using this property you can choose whether 'KeyFont1' and 'KeyFont2' are used as
defined, or whether only the 'Color' and 'Style' properties of these fonts are used.
Especially when dealing with large files with many keywords it saves some time
when loading a file if you set this property to false.


property Syntaxhervorhebung: Boolean

This property is used to switch syntax highlighting on an off.


property OnTopLineChange: TNotifyEvent

This is a new event that has nothing to do with the syntax highlighting ability.
It is fired every time the first visible line changes.


3. New methods

There are a number of new methods in 'TXRichEdt' that are supposed to make using
the editor a little easier.


procedure LoadFromFile(const Name:string); virtual;
procedure SaveToFile(const Name:string); virtual;

These methods should be used instead of Lines.LoadFromFile and Lines.SaveToFile:
After loading the text, it has to be processed to activate the syntax highlighting
and this is done by 'LoadFromFile'.

Remark: When loading a large file with many keywords, this process may take a while.
This is why this component is intended to be used with smaller files only.


function GetCurrentWord : string;

This method returns the current word. The letters that make up words are defined via
the 'letters' property.


function GetCaretPosition(var Col:Integer) : Integer;

This method retrieves the position of the cursor; 'Col' is the column, the return
value indicates the line. If the cursor is at the very beginning of the text, both
values are 1.


4. Implementation

Usually, syntax highlighting is done like this: The data is stored internally as
plain text; when a portion of the text has to be displayed, the text is being parsed
(basically the program is looking for keywords) and different colors are used to
show the text on screen.

However, you have to write a new editor-component from scratch to pursuit this
approach.

The idea here was to use 'TRichEdit' - which means that you have a nice editor and
the only task left is to add syntax highlighting. The main drawback is that you have
to use a different approach to reach this goal: In 'TXRichEdt', the property
'SelAttributes' has to be used to tag every keyword within the text - this has to
be done when a file is being loaded and may take a while.

When editing, 'TXRichEdt' has to monitor which part of the text is being modified
and has to change the attributes of the text subsequently. (This does not result
in a significant delay as only a very limited part of the text has to be
reformatted).


5. Final remark

If you have any comments regarding this component send an email to
[email protected]