Managing Tables in C++

General TRichView support forum. Please post your questions here
Post Reply
Benna
Posts: 3
Joined: Tue Aug 10, 2010 2:49 pm

Managing Tables in C++

Post 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
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
Benna
Posts: 3
Joined: Tue Aug 10, 2010 2:49 pm

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Benna
Posts: 3
Joined: Tue Aug 10, 2010 2:49 pm

Post 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
Post Reply