Product Documentation

VCL/CLX Developers Guide

Previous Topic

Next Topic

Adding an Existing Table to a Database

A table may belong to multiple databases. A table may be created in one database and later added to a second one. Current or new c-tree Plus files may also be added to a database, with a few exceptions (see the discussion in Chapter 12 “Existing c-tree Plus Data Considerations” in the c-tree Plus Quick Start and Product Overview Guide). Use the following procedure to add an existing table named MyOldTable (in the specified directory) to a database in run time:

  1. Log on to a c-tree Plus session (please refer to “Log On to c-tree”).
  2. Connect to a database (please refer to “Connecting to a database”).
  3. Drop a TCtTable component on a form.
  4. Set the Table property to the table name.
  5. Set the Database property to the database component.
  6. Set the Directory property to point to a location where the table is stored.
  7. Call the AddTable() method.

The code excerpts below represent a table being added to a database at run time. There is no way to add a table at design time.

Delphi Example


procedure Form1.AddExistingTable();

begin

try

CtTable1.Table := MyOldTable;

CtTable1.Database := CtDatabase1;

{$IFDEF WIN32} // Windows path

CtTable1.Directory := 'C:\Data';

{$ELSE} // Linux path

CtTable1.Directory := '/home/Data';

{$ENDIF}

CtTable1.AddTable();

except

on E : ECtError do

Application.ShowException(E);

end;

end;

C++ Example


void Form1::AddExistingTable()

{

try

{

CtTable1->Table = "MyOldTable"

CtTable1->Database = CtDatabase1;

#ifdef __WIN32__ // Windows path

CtTable1->Directory = "C:\\Data";

#else // Linux path

CtTable1->Directory = "/home/Data";

#endif

CtTable1->AddTable();

}

catch (ECtError& E)

{

Application->ShowException(&E);

}

}

TOCIndex