RichView, add multi colored line without table

General TRichView support forum. Please post your questions here
Post Reply
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

RichView, add multi colored line without table

Post by reiser »

Hi all.

How can I add multi colored line to TRichView, without using table?

I want to achieve same effect as when I add multicolored line to normal RichEdit control, so user can select text normally. I need to add line that looks like this mainly:
<username> message
Thanks!
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

Post by reiser »

Also, I found out adding new row to table is very cpu intensive, to the point where whole GUI stutters for a moment while code that adds new row executes. This is how I add it:

Code: Select all

    table := frmDebug.rvLog.RVData.GetItem(0) as TRVTableItemInfo;

    if table.RowCount = 0 then
    begin
      table.InsertRows(0, 1, -1, FALSE);
      table.InsertCols(0, 3, -1, FALSE);
      table.Rows[0].Items[0].BestWidth := 75;
      table.Rows[0].Items[1].BestWidth := 75;
    end
    else
      table.InsertRows(table.RowCount, 1, 0, FALSE);

    frmDebug.rvLog.Format;

    table.Cells[table.RowCount - 1, 0].Clear;
    table.Cells[table.RowCount - 1, 1].Clear;
    table.Cells[table.RowCount - 1, 2].Clear;

    table.Cells[table.RowCount - 1, 0].AddFmt('%s', [time_str], 0, 0);
    table.Cells[table.RowCount - 1, 1].AddFmt('%s', [type_str], tstyle, 1);
    table.Cells[table.RowCount - 1, 2].AddFmt('%s', [AData], dstyle, 2);

    frmDebug.rvLog.Format;
    frmDebug.rvLog.VScrollPos := frmDebug.rvLog.VScrollMax;
And this is how I create table (in OnCreate even of the form):

Code: Select all

  table := TRVTableItemInfo.CreateEx(0, 0, rvLog.RVData);
  with table do
  begin
    BorderWidth := 0;
    CellVPadding := 0;
    CellBorderWidth := 0;
    CellVSpacing := 0;
    BorderVSpacing := 0;
    Color := clNone;
    BestWidth := 0;
    Options := [rvtoRTFAllowAutofit];
  end;
  rvLog.AddItem('ContentTable', table);
Is there way to optimize this?
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

Post by reiser »

I use latest version of RichView btw.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You can speed up this code if you remove the first call of Format.
It will still be slow, because Format reformats the whole document.

The code can be made fast, if you will add a new table each time instead of adding a new row, and format using FormatTail instead of Format.
However, it will increase memory usage, so I recommend this approach only for relatively small documents.

---

As for line coloring, you can use text background (RVStyle.TextStyles[].BackColor property.
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

Post by reiser »

I know about line coloring, but how can I add multicolored TEXT in one line? Without using table. So, text would need to act like "raw" data, instead columned data.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Code: Select all

rv.AddNL(time_str+' ', 0, 0); 
rv.AddNL(type_str+' ', tstyle, -1); 
rv.AddNL(AData, dstyle, -1); 
or

Code: Select all

rv.AddNL(time_str+' ', 0, 0); 
rv.Add(type_str+' ', tstyle); 
rv.Add(AData, dstyle); 
I assume that 0-th, tstyle-th, dstyle-th text styles have different backgrounds.
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

Post by reiser »

Thats what I needed. Thanks!
Post Reply