Use the following procedure to create a new database at design time:
The last operation above will connect to the database and create the database dictionary. It is important to disconnect from the database before closing the application, and this is done automatically by c-treeVCL/CLX when the user logs off from the session.
To create a database dictionary at run time, drop a session component and a database component on the form, perform a Session logon, and create a procedure with the following steps:
When creating the database at run time, as shown below, it is not required to connect to the database.
The sequences below represent the run time creation of a database dictionary in Delphi and C++.
Delphi Example
procedure Form1.CreateNewDatabase;
begin
try
CtDatabase1.Database := 'MyData';
{$IFDEF WIN32} // Windows path
CtDatabase1.Directory := 'C:\Data';
{$ELSE} // Linux path
CtDatabase1.Directory := '/home/Data';
{$ENDIF}
CtDatabase1.Session := CtSession1;
CtDatabase1.CreateDatabase();
except
on E : ECtError do
Application.ShowException(E);
end;
end;
C++ Example
void Form1::ConnectToDatabase()
{
try
{
CtDatabase1->Database = "MyData";
#ifdef __WIN32__ // Windows path
CtDatabase1->Directory = "C:\\Data";
#else // Linux path
CtDatabase1->Directory = "/home/Data";
#endif
CtDatabase1->Session = CtSession1;
CtDatabase1->CreateDatabase();
}
catch (ECtError& E)
{
Application->ShowException(&E);
}
}