Product Documentation

VCL/CLX Developers Guide

Previous Topic

Next Topic

Adding an Existing Database

A database that has been dropped from the session may be added back. Use the following procedure to add an existing database to a session at run 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 with the location where the database dictionary is stored. If this location is invalid, there will be no error in the add operation, but the application will fail to connect to this database.
  5. Set the Session property with the Session component.
  6. Call the AddDatabase() method.

Delphi Example


procedure Form1.AddExistingDatabase;

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.AddDatabase();

except

on E : ECtError do

Application.ShowException(E);

end;

end;

C++ Example


void Form1::AddExistingDatabase()

{

try

{

CtDatabase1->Database = "MyData";

#ifdef __WIN32__ // Windows path

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

#else // Linux path

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

#endif

CtDatabase1->Session = CtSession1;

CtDatabase1->AddDatabase();

}

catch (ECtError& E)

{

Application->ShowException(&E);

}

}

TOCIndex