HELP ! Colored memo (with different backgrounds)

Hello,

I'm writing a chat client under Delphi 2.0
It looks already pretty fine, however, one thing that bothers me is the
displaying of channel/private messages -
I haven't used a component since I didn't find one which can display several
colors - and important - different BACKGROUNDS. The TColorMemo didn't work
for me.

So there's an own drawing routine, it works quite okay, but with time it
gets damn slow (especially when there is much text to display):

I have included a sample of the code.
It would be great if someone could help me to make this faster and/or with
a working component that supports background colors, too.
Please email me @ t...@softhome.net!

Thanks very much in advance.

Cheers,
(=: Tobi :=)

-------------------------------------
(code follows)
-------------------------------------
procedure TfrmChannel.MyTextPaint(Sender: TObject);
var LinesShown : integer;  { number of lines in paintbox }
   Rect : TRect;
   i, Snr : integer;
   ForeColor, BackColor: Integer;
   XP, F, G, tmpInt, tmpInt2: Integer;
   tmpString2, tmpString, Line : string;
begin
   LinesShown := MyText.Height div MyText.Canvas.TextHeight('H');
   MyText.Canvas.Brush.Style := bsSolid;
   MyText.Canvas.Font.Name := ChanFont.Name;
   MyText.Canvas.Font.Size := ChanFont.Size;
   for i := 0 to LinesShown-1 do begin
      MyText.Canvas.Font.Style := ChanFont.Style;
      { paint each line }
      { which string is at line i of the paintbox?? }
      tmpInt:=0;
      tmpInt2:=0;
      Snr := i-(LinesShown-1) + ScrBar.Position;
      if (Snr < 0) or (Snr >= ChanLines.Count) then
         Line := ''
      else
         Line := ChanLines[Snr];
      { now paint this line }

       BackColor:=1;
       ForeColor:=0;
       for XP:=1 to Length(Line) do begin
         tmpInt2:=tmpInt2+1;
         tmpString:=Copy(Line,TmpInt2,1);
         if tmpString=#141 then begin
           tmpString2:=Copy(Line,TmpInt2+1,1);
           Val(tmpString2,F,G);
           if G<>0 then begin F:=0; BackColor:=1 end
             else TmpInt2:=TmpInt2+1;
           if F=1 then begin
             tmpString2:=Copy(Line,TmpInt2+1,1);
             Val(tmpString2,F,G);
             if G=0 then begin F:=10+F; tmpInt2:=TmpInt2+1; end
             else F:=1;

           end;
           ForeColor:=F;

           tmpString2:=Copy(Line,TmpInt2+1,1);
           if tmpString2=',' then begin
             tmpInt2:=tmpInt2+1;
             tmpString2:=Copy(Line,TmpInt2+1,1);

             Val(tmpString2,F,G);
             if G<>0 then F:=1 else begin
               TmpInt2:=TmpInt2+1;
               if F=1 then begin
                 tmpString2:=Copy(Line,TmpInt2+1,1);
                 Val(tmpString2,F,G);
                 if G=0 then begin F:=10+F; tmpInt2:=TmpInt2+1; end
                 else F:=1;

               end;
             end;
             BackColor:=F;
           end;
         end
         else if tmpString=#9 then begin
           tmpInt:=tmpInt+MyText.Canvas.TextWidth('8')*3;
         end
         else if tmpString=#142 then begin
           if fsBold in MyText.Canvas.Font.Style then
             MyText.Canvas.Font.Style:=MyText.Canvas.Font.Style - [fsBold]
           else
             MyText.Canvas.Font.Style:=MyText.Canvas.Font.Style + [fsBold];
         end
         else if tmpString=#143 then begin
           if fsItalic in MyText.Canvas.Font.Style then
             MyText.Canvas.Font.Style:=MyText.Canvas.Font.Style - [fsItalic]
           else
             MyText.Canvas.Font.Style:=MyText.Canvas.Font.Style + [fsItalic];
         end
         else if tmpString=#144 then begin
           if fsUnderline in MyText.Canvas.Font.Style then
             MyText.Canvas.Font.Style:=MyText.Canvas.Font.Style -
[fsUnderline]
           else
             MyText.Canvas.Font.Style:=MyText.Canvas.Font.Style +
[fsUnderline];
         end;

      if (tmpString<>#141) and (tmpString<>#9)
        and (tmpString<>#142) and (tmpString<>#143) and (tmpString<>#144)
then begin
        if fsBold in MyText.Canvas.Font.Style then begin
          MyText.Canvas.Font.Style:=MyText.Canvas.Font.Style - [fsBold];
          Rect.TopLeft := Point(tmpInt, MyText.Height-(LinesShown-1-i+1)
*MyText.Canvas.TextHeight('H'));
          Rect.BottomRight := Point(tmpInt+MyText.Canvas.TextWidth
(tmpString), Rect.Top + MyText.Canvas.TextHeight('H'));
          MyText.Canvas.Font.Style:=MyText.Canvas.Font.Style + [fsBold];
        end else begin
          Rect.TopLeft := Point(tmpInt, MyText.Height-(LinesShown-1-i+1)
*MyText.Canvas.TextHeight('H'));
          Rect.BottomRight := Point(tmpInt+MyText.Canvas.TextWidth
(tmpString), Rect.Top + MyText.Canvas.TextHeight('H'));
        end;

        if BackColor=1 then MyText.Canvas.Brush.Color := clWhite
         else MyText.Canvas.Brush.Color := GetTheColor(BackColor);
        MyText.Canvas.Font.Color := GetTheColor(ForeColor);
        MyText.Canvas.FillRect(Rect);
        MyText.Canvas.TextOut(Rect.Left, Rect.Top, tmpString);
        tmpint:=tmpint+mytext.canvas.textwidth(tmpString);
      end;
    end;
   end;
end;

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading