Sergey, I pose the following query:
I have a document that contains a table which I will add rows as needed, reviewing the documentation, you should use table.InsertRowsBelow (nroRows), the question is: how to reference the table object to use InsertRowsBelow, and that the object was created when creating the template code.?
Thanks.
Adding rows to an existing table
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Sorry, I do not understand your answer.
However, I'll give some examples.
Example 1
How to add a row to the end of the current table.
("a current table" is a table at the caret position; the caret may be to the left or to the right of this table, or inside its cell; or the caret may be hidden but several cells of this table are selected).
The example assumes that the table is inserted in RichViewEdit1.
This is an editing operation, it can be undone by the user.
Example of other table operations (adding/deleting rows and columns, merging and unmerging cells) can be found in the Demos\Editors\Editor 1\ demo, menu "Table"
However, I'll give some examples.
Example 1
How to add a row to the end of the current table.
("a current table" is a table at the caret position; the caret may be to the left or to the right of this table, or inside its cell; or the caret may be hidden but several cells of this table are selected).
The example assumes that the table is inserted in RichViewEdit1.
This is an editing operation, it can be undone by the user.
Code: Select all
var table: TRVTableItemInfo;
Data: Integer;
rve: TCustomRichViewEdit;
ItemNo: Integer;
begin
if RichViewEdit1.GetCurrentItemEx(TRVTableItemInfo, rve, TCustomRVItemInfo(table)) then begin
ItemNo := rve.GetItemNo(table);
rve.BeginItemModify(ItemNo, Data);
table.InsertRows(table.RowCount, 1, table.RowCount-1, False);
rve.EndItemModify(ItemNo, Data);
rve.Change;
end;
end;
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Example 2
Adding a row to the end of the first table in the document.
This is an editing operation, it can be undone by user.
Example 3
The same code for TRichView instead of TRichViewEdit.
Adding a row to the end of the first table in the document.
Code: Select all
// TableNo - index of table. 0 for the first table, 1 for the second, and so on
function GetTableItemNo(RVData: TCustomRVData; TableNo: Integer): Integer;
var i: Integer;
begin
Result := -1;
for i := 0 to RVData.ItemCount-1 do
if RVData.GetItemStyle(i)=rvsTable then begin
if TableNo=0 then begin
Result := i;
exit;
end;
dec(TableNo);
end;
end;
var table: TRVTableItemInfo;
Data: Integer;
ItemNo: Integer;
begin
ItemNo := GetTableItemNo(RichViewEdit1.RVData, 0);
if ItemNo<0 then
exit;
table := TRVTableItemInfo(RichViewEdit1.GetItem(ItemNo));
RichViewEdit1.BeginItemModify(ItemNo, Data);
table.InsertRows(table.RowCount, 1, table.RowCount-1, False);
RichViewEdit1.EndItemModify(ItemNo, Data);
RichViewEdit1.Change;
end;
Example 3
The same code for TRichView instead of TRichViewEdit.
Code: Select all
var table: TRVTableItemInfo;
ItemNo: Integer;
begin
ItemNo := GetTableItemNo(RichView1.RVData, 0);
if ItemNo<0 then
exit;
table := TRVTableItemInfo(RichView1.GetItem(ItemNo));
table.InsertRows(table.RowCount, 1, table.RowCount-1, False);
RichView1.Format;
end;