Product Documentation

VCL/CLX Developers Guide

Previous Topic

Next Topic

Creating a New Database

Use the following procedure to create a new database at design time:

  1. Log on to a c-tree Plus session (refer to “Log On to c-tree”).
  2. Drop a TCtDatabase component on a form.
  3. Set the Database property to the database name.
  4. Set the Directory property to the location where the database dictionary will be stored, if different from the default (server directory for client/server and application directory for non-server applications).
  5. Set the Session property to the Session component.
  6. Set the AutoCreate property to True.
  7. Set the Active property to True.

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:

  1. Set the Database property to the database name.
  2. Set the Directory property to the location where the database dictionary will be stored.
  3. Set the Session property to the Session component.
  4. Call the CreateDatabase() method.

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);

}

}

TOCIndex