Page 1 of 1
Managing Tables in C++
Posted: Tue Aug 10, 2010 2:56 pm
by Benna
Hi all, i'm starting to use this amazing component but i have quite some questions about managing tables.
I did a simple test form with the component TRichVieEdit and a button that creates a table.
Table is created correctly, now i wnat to manage that table such has adding or deleting columns/rows via a new button
Code: Select all
TRVTableItemInfo *table = new TRVTableItemInfo(nRow, nCol, pRichView->RVData);
table->Color = clYellow;
pRichView->InsertItem (tName, table);
where pRichView it's a pointr inside my class.
The problem now is: how can i reference to my table already created in order to add rows/columns?
i mean, i've seen the examples:
Code: Select all
procedure InsertRows(Index, Count, CopyIndex: Integer);
but i supose it would be something like
Code: Select all
MyTable.InsertRows(Index, Count, CopyIndex: Integer);
But i don't know how to reference my existing table.
How i've been clear, anyway just tell me and i'll provide new examples.
Thanks
Posted: Tue Aug 10, 2010 3:29 pm
by Sergey Tkachenko
If you need to get a table at the caret position use GetCurrentItemEx method. The example can be found in Demos\CBuilder\Editors\Editor 1\
(or in Demos\CBuilderUnicode\Editors\Editor 1\, if you use C++Builder 2009 or 2010)
Posted: Thu Aug 12, 2010 8:21 am
by Benna
I want to create a method inside my class called
Code: Select all
TRVTableItemInfo * GetTable(AnsiString TableName)
returning a pointer to a table already created in the past.
This method will be used inside aother method, for example:
Code: Select all
void clsRichView::AddColRight(int nCol)
{
TRVTableItemInfo *table;
table = GetTable(nTable);
table->InsertColsRight(nCol);
pRichView->Format();
}
This method would add column on the right for an existing table.
On the PDF help file i've found something i suppose can help me but i still have problems.
I would like to get the table pointer via the table name (AnsiString) specified with the method InsertItem.
So i did something like this:
Code: Select all
TRVTableItemInfo *table;
int i;
for (i = 0; i<pRichView->RVData->ItemCount; i++)
{
if (pRichView->RVData->GetItemStyle(i) == rvsTable)
{
if (pRichView->RVData->GetItem(i)->ItemText == TableName)
{
table = &TRVTableItemInfo(pRichView->RVData->GetItem(i));
return table;
}
}
}
I suppose this is the way to use the Table Name i've specified during Table creation in order to get the object (since in my document i can have more than one Table created).
The only problem right now is to assign to table (a pointer) the address of the object return by TRVTableItemInfo(pRichView->RVData->GetItem(i)). I get error.
I'm not interested in getting the table where the carret is located.
Posted: Thu Aug 12, 2010 10:18 am
by Sergey Tkachenko
Correction:
Code: Select all
TRVTableItemInfo *table;
int i;
for (i = 0; i<pRichView->RVData->ItemCount; i++)
{
if (pRichView->RVData->GetItemStyle(i) == rvsTable)
{
if (pRichView->RVData->GetItem(i)->ItemText == TableName)
{
table = [color=red](TRVTableItemInfo*)[/color](pRichView->RVData->GetItem(i));
return table;
}
}
}
This code will return existing table only if it is not nested (not inside another table).
If you need a code for returning table even if it is nested, let me know.
Posted: Thu Aug 12, 2010 11:13 am
by Benna
Thanks Sergey, i've solved using this statement:
Code: Select all
return dynamic_cast<TRVTableItemInfo *>(pRichView->RVData->GetItem(i))
Right now i think i'm ok, if i had the need you've mention i'll let you know.
Thanks again so much