[Lazarus] Displaying text with colour and insertion point
lazarus at mfriebe.de
Wed May 16 16:27:57 CEST 2012
On 16/05/2012 14:13, Mark Morgan Lloyd wrote:
> Martin wrote:
>> The normal way (see example):
>> // Line 0, from start of line to pos 3 (3 chars) highlighted as
>> but this will do a single char
>> Highlighter.AddToken(0,3,Attr1); // Attr1 from col 3
>> Highlighter.AddToken(0,4,tkText); // text from col 4
> I don't think any sort of pre-existing custom highlighter will work.
> The requirement here is that anything- completely context-free- that
> the user enters is red, anything that the host supplies (over telnet,
> serial line etc.) is black. Either of those can be complete garbage,
> but should still show up in the correct colour (and should stay
> correct, irrespective of scrolling etc.).
The position highlighter refers to position in text. Scrolling via
scrollbar is no problem.
But if you add/remove lines; or add/remove chars in a line, you must
update the positions.
I assume you have a fixed amount of lines and columns? If so it should
be very simple to write a pos-highlighter (part of your project, does
not need to be registerred in IDE), that has
CharAttributes: Array[1..maxLine] of array [ 1..MaxColumn] of TAttribute
Of course that is not practical if you have thousands of lines, as it
would require a lot of storage....
> In practice (in this particular project) I'm stuffing characters
> directly into the items/lines property (of whichever output component
> I'm using). In other words I'm not using any of the component's own
> keyboard handling, the reason is that there are several stages of
> translation in between the user pressing a key and it being printed.
SynEdit has a read only property. But that still allows selection and
moving the caret.
If needed it can be configured to ignore all user input (the previews in
the IDE option do that). That is srollbars can always be scrolled...
More information about the Lazarus