Row cloning
Row cloning
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.
- 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.
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Table has undocumented methods SaveRowsToStream and LoadFromStreamEx.
You can use them to copy rows:
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:
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;
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;
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: