Page 1 of 1
Row cloning
Posted: Thu Feb 14, 2008 11:34 am
by Nofate
I have the following problem:
- I need to walkthrough a table
- if table has any row containing text of a defined color (i.e. $0000ff) - duplicate this row.
Can you suggest any working solution?
Thanks.
Posted: Thu Feb 14, 2008 1:24 pm
by Sergey Tkachenko
Do you want to add a new row in the same table? After the source row or to the end? Should it be an editing operation (undoable) or not?
Posted: Thu Feb 14, 2008 2:13 pm
by Nofate
Yes, I want to insert row into the same table just after the source row.
It shouldn't be an editing operation.
And I can't get idea how to get color of the text fragment in cell.
Posted: Fri Feb 15, 2008 7:47 am
by Nofate
May be it will be easier to suggest a solution if i describe general task.
I need to fill table having only one row with tags like "[name]","[job]" etc with values from dataset.
Posted: Fri Feb 15, 2008 7:49 am
by Nofate
May be it will be easier to suggest a solution if i describe general task.
I need to fill table having only one row containing tags like "[name]","[job]" etc with values from dataset.
Posted: Sat Feb 16, 2008 12:38 pm
by Sergey Tkachenko
Table has undocumented methods SaveRowsToStream and LoadFromStreamEx.
You can use them to copy rows:
Code: Select all
var Stream: TMemoryStream;
Row: Integer;
begin
Row := 0;
Stream := TMemoryStream.Create;
table.SaveRowsToStream(Stream, Row, 1);
Stream.Position := 0;
table.InsertRows(Row+1, 1, 0, False);
table.LoadFromStreamEx(Stream, Row+1);
Stream.Free;
Note that if table is inserted in the editor, InsertRows becomes and editing operation. So call the code before inserting the table, or call ClearUndo when finished.
As for recognizing if the row has cell having text of the given color:
Code: Select all
function RowHasTextColor(RVStyle: TRVStyle; table: TRVTableItemInfo; Row: Integer; Color: TColor): Boolean;
var c, i, StyleNo: Integer;
begin
Result := True;
for c := 0 to table.ColCount-1 do
if table.Cells[Row,c]<>nil then
for i := 0 to table.Cells[Row,c].GetRVData.ItemCount-1 do begin
StyleNo := table.Cells[Row,c].GetRVData.GetItemStyle(i);
if (StyleNo>=0) and (RVStyle.TextStyles[StyleNo].Color=Color) then
exit; // found
end;
Result := False;
end;
Posted: Mon Feb 18, 2008 9:24 am
by Nofate
Thanks
Posted: Mon Feb 18, 2008 9:46 am
by Nofate
LoadFromStreamEx() raises exception EReadError with message 'Wrong end of cells list' in method TRVTableItemInfo.CellsReader() after "if not Reader.EndOfList"
Posted: Tue Feb 19, 2008 9:07 am
by Sergey Tkachenko
Probably you copy to the row having different number of cells. Probably because of cell merging.