Board index » delphi » RichEdit SetAttributes.Color ...

RichEdit SetAttributes.Color ...

Hello

How can I, while working with Richedit, change the colour of certain code
words?

The filtering of a word, already fails when using the function WordAtCursor
(further down),
because lines and commas are not recognised as dividers (can you add a
divider?)

Alternatively I tried to change the complete text to Standard-colour and
afterwards used the command FINDTEXT to find all code words and then using
SelStart, SelLength and
SetAttributes.Color to change the colour of the code words. The result of
this procedure was that the text scrolled and working was impossible. Can
the scrolling be stopped?

Thanks

Function WordAtCursor: string;
var
  Range: TCharRange;
begin
  Result := '';
  if HandleAllocated then begin
    Range.cpMax := SelStart;
    if Range.cpMax = 0 then Range.cpMin := 0
    else if SendMessage(Handle, EM_FINDWORDBREAK, WB_ISDELIMITER,
Range.cpMax) <> 0 then
      Range.cpMin := SendMessage(Handle, EM_FINDWORDBREAK, WB_MOVEWORDLEFT,
Range.cpMax)
    else
      Range.cpMin := SendMessage(Handle, EM_FINDWORDBREAK, WB_LEFT,
Range.cpMax);
    while SendMessage(Handle, EM_FINDWORDBREAK, WB_ISDELIMITER, Range.cpMin)
<> 0 do
      Inc(Range.cpMin);
    Range.cpMax := SendMessage(Handle, EM_FINDWORDBREAK, WB_RIGHTBREAK,
Range.cpMax);
    Result := Trim(GetTextRange(Range.cpMin, Range.cpMax));
  end;
end;

 

Re:RichEdit SetAttributes.Color ...


Quote
In article <3b39d4af_1@dnews>, Dirk Schauries wrote:
> How can I, while working with Richedit, change the colour of certain code
> words?

Dirk,

many have tried to go that way and finally given up in disgust (at least those
that managed to keep sane <g>). Trichedit is simply not suited for things like
on-the-fly syntax highlighting since you cannot examine or change text
attributes without selecting the text first. Effective syntax highlighting
needs to be done in the drawing code and that is not modifiable in a richedit.

You may want to look at some 3rd-party stuff. I don't know if all of the ones
listed below support syntax highlighting.

 TColorMemo              http://www.balticsolutions.com
 TSyntaxMemo             http://www.dbrocksoftware.com
 TDreamMemo              http://www.dreamcompany.com/
 synEdit (ex. mwEdit)    http://synedit.sourceforge.net/
 TPlusMemo               http://www.scientifique.com/ecm

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Re:RichEdit SetAttributes.Color ...


What is the problem with selecting a range? You can disable the DISPLAY of the
hightlited selection so that you dont see it going on in the background.

Davie

Quote
"Peter Below (TeamB)" wrote:
> In article <3b39d4af_1@dnews>, Dirk Schauries wrote:
> > How can I, while working with Richedit, change the colour of certain code
> > words?

> Dirk,

> many have tried to go that way and finally given up in disgust (at least those
> that managed to keep sane <g>). Trichedit is simply not suited for things like
> on-the-fly syntax highlighting since you cannot examine or change text
> attributes without selecting the text first. Effective syntax highlighting
> needs to be done in the drawing code and that is not modifiable in a richedit.

> You may want to look at some 3rd-party stuff. I don't know if all of the ones
> listed below support syntax highlighting.

>  TColorMemo              http://www.balticsolutions.com
>  TSyntaxMemo             http://www.dbrocksoftware.com
>  TDreamMemo              http://www.dreamcompany.com/
>  synEdit (ex. mwEdit)    http://synedit.sourceforge.net/
>  TPlusMemo               http://www.scientifique.com/ecm

> Peter Below (TeamB)  100113.1...@compuserve.com)
> No e-mail responses, please, unless explicitly requested!
> Note: I'm unable to visit the newsgroups every day at the moment,
> so be patient if you don't get a reply immediately.

Other Threads