trichview.com

trichview.support




Re: Help with highliting text


Return to index


Author

Message

Sergey Tkachenko

Posted: 11/30/2003 20:51:44


Well, this is not so trivial (coloring the text completely, like they

usually do in similar cases) would be much more easy.


Ok, it looks like the code below works. But do not use it for very large

documents.

It assumes that the normal text attributes is in TextStyles[0], and red text

is in TextStyles[1].


This code uses RVLinear unit. It is included in registered version of

components, or can be downloaded here:

http://www.trichview.com/support/files/rvlinear.zip


// RichViewEdit1.OnChange


procedure TForm3.RichViewEdit1Change(Sender: TObject);

var SelStart, SelLength, Len: Integer;

const Busy: Boolean = False;

   MAXLEN = 300;

begin

  if not Busy then begin

    Busy := True;

    LockWindowUpdate(RichViewEdit1.Handle);

    try

      RVGetSelection(RichViewEdit1, SelStart, SelLength);

      with RichViewEdit1 do

        SetSelectionBounds(ItemCount-1, GetOffsAfterItem(ItemCount-1),

          ItemCount-1, GetOffsAfterItem(ItemCount-1));

      Len := RVGetLinearCaretPos(RichViewEdit1)-1;

      if Len>MAXLEN then begin

        RVSetSelection(RichViewEdit1, 1, MAXLEN);

        RichViewEdit1.ApplyTextStyle(0);

        RVSetSelection(RichViewEdit1, 1+MAXLEN, Len-MAXLEN);

        RichViewEdit1.ApplyTextStyle(1);

        end

      else begin

        RichViewEdit1.SelectAll;

        RichViewEdit1.ApplyTextStyle(0);

      end;

      RVSetSelection(RichViewEdit1, SelStart, SelLength);

    finally

      LockWindowUpdate(0);

    end;

    Busy := False;

  end;

end;





Powered by ABC Amber Outlook Express Converter