Link to home
Start Free TrialLog in
Avatar of raunol
raunolFlag for Finland

asked on

Is it possible to change a line color of a RichEdit without selection?

Is it possible to change a line color of a RichEdit without selection?
ASKER CERTIFIED SOLUTION
Avatar of ZifNab
ZifNab

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of raunol

ASKER

Hi,

Good idea! Thank You very much, Zif.

It works just like I want, a selection not
flashes during colouring. I feel that Perform
function is rather nicer code to use than Sendmessage,
like this:

//colouring of the current line
Procedure TForm1.Button1Click(Sender: TObject);
var
    iStart, iEnd: longint;
    iSelStart, iSelEnd: longint;
    CurrentLine:Longint;
Begin
Whit RichEdit1 do
Begin
               Lines.BeginUpdate;  
      Perform(EM_GETSEL, LongInt( @iStart ), LongInt( @iEnd ));
               //Get the current line
      CurrentLine:=Perform(EM_LINEFROMCHAR,SelStart,0);
      //Starpos in the begin of the line
            iSelStart:= Perform(EM_LINEINDEX,CurrentLine, 0 );
                 iSelEnd := iSelStart+Length(Lines[CurrentLine]);
            Perform(EM_SETSEL, iSelStart, iSelEnd );
            // change the color of the text
            SelAttributes.Color := clRed;
            // return to saved position
            Perform(EM_SETSEL, iStart, iEnd );
            Lines.EndUpdate;
      Setfocus;
End;


- Rauno


Avatar of ZifNab
ZifNab

Yep Rauno, it's nicer with perform. regards, ZiF.
Avatar of raunol

ASKER

Hi, Zif

Thanks for Your comment. Dont be sorry, but
in fact, I was glad too early. The selection
still flashes when to colour a line which is
longer. So Your answer wasn't perfect for my problem:
How to colour line without selection.

Anyway You gave a good advice using of api
functions.


- Rauno



Sorry, it doesn't works. I'll look for a solution.
Avatar of raunol

ASKER

Hi, Zif

Now, I found a one solution my self.

First we must add "RichEdit" -unit to USES section

Then it's possible to use Sendmessage or
perform function:
RichEdit1.Perform(EM_HIDESELECTION,1,0)
And voila! No selection flashes during colouring.

- Rauno

Hi Rauno,

Great solution! Thanks for letting me know of this!

Regards Zif.