Page 1 of 1
RichView, add multi colored line without table
Posted: Sun Mar 16, 2014 8:24 pm
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!
Posted: Mon Mar 17, 2014 5:48 am
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?
Posted: Mon Mar 17, 2014 5:59 am
by reiser
I use latest version of RichView btw.
Posted: Mon Mar 17, 2014 10:29 am
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.
Posted: Mon Mar 17, 2014 11:39 am
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.
Posted: Mon Mar 17, 2014 12:21 pm
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.
Posted: Mon Mar 17, 2014 2:54 pm
by reiser
Thats what I needed. Thanks!