It is necessary to connect to a database before creating a c-tree Plus table and/or manipulating data stored in a c-tree Plus table. To connect to a database at design time, execute the following steps:
The database path is not required in order to connect to the database. This information is stored in the session dictionary.
When the database connection is no longer necessary, disconnect from the database by setting the Active property to False or by calling the Disconnect() method.
To connect to a database at run time, execute the following steps after the TCtDatabase component has been dropped on the form:
The sequences below represent the run time connection to the database dictionary in Delphi and C++.
Delphi Example
procedure Form1.ConnectToDatabase;
begin
try
CtDatabase1.Database := 'MyData';
CtDatabase1.Session := CtSession1;
CtDatabase1.Connect();
except
on E : ECtError do
Application.ShowException(E);
end;
end;
C++ Example
void Form1::ConnectToDatabase()
{
try
{
CtDatabase1->Database = "MyData";
CtDatabase1->Session = CtSession1;
CtDatabase1->Connect();
}
catch (ECtError& E)
{
Application->ShowException(&E);
}
}
Once again, it is important to disconnect from the database before closing the application. If, for any reason, the user logs off from the session, the database is automatically disconnected. To disconnect a database, either set its Active property to False or call the Disconnect method. It is also possible to disconnect from all active databases at once using the TCtSession DisconnectAll() method.