Previous Topic

Next Topic

Creating a Table object

A valid table object is required before most table operations can take place. You need to pass a valid CTDatabase object to the CTTable constructor.

// create a CTTable object
CTTable ATable(ADatabase);
try
{
// open table “MyTable”
ATable.Open(“MyTable”, CTOPEN_NORMAL);
}
catch (CTException &err)
{
printf(“Table open failed with error %d\n”, err.GetErrorCode);
}

If you create a dynamic CTTable object with the new operator, you are required to destroy the object with the delete operator.

// create a dynamic CTTable object
CTTable* pTable = new CTTable(ADatabase);

if (!pTable)
{
   printf(“CTTable creation failed\n”);
}  
... other operations ..
// destroy the CTTable object
delete pTable;

If you destroy an active table object, all record objects associated with the table will be reset and the table closed before the object is destroyed.