Product Documentation

VCL/CLX Developers Guide

Previous Topic

Next Topic

Creating a new session

The c-treeVCL/CLX interface requires a session to perform any data structure initialization or manipulation. All database information is stored inside the session dictionary, ctdbdict.fsd, which is located by default either in the server directory (client/server application) or in the application directory (stand-alone application).

A session dictionary must exist to initialize c-treeVCL/CLX, and the user must logon to a session to operate on a database.

If the user tries to create a session dictionary and one already exists in the desired directory, an error or exception will occur. The same session dictionary (as well as the database dictionaries) may be used in both standalone and client/server environments, although it is not a good practice to use both at the same time, since no files should be opened by the server and a stand-alone application at the same time.

To create a new session dictionary at design time, take the following steps:

  1. Drop a TCtSession component on the form.
  2. Set the Server, User, and Password properties as appropriate.
  3. Set the Directory property to point to a directory where the session dictionary file will be created, if different from the default (server directory for client/server and application directory for non-server applications).
  4. Set the AutoCreate property to True.
  5. Set the Active property to True.

The last operation above will also logon to the server, besides creating the session dictionary. When using the client/server model, the server must be active before the Active property is set to true. If this is not the case, an exception will be thrown with error ASKY_ERR (133), indicating the server is not active. It is important to log off from the server before closing the application, and this can be done setting the Active property to False at any time, for instance, in the form's OnClose() event.

To create a new session dictionary at run time, create a procedure with the following steps (after the TCtSession component is dropped on the form):

  1. Set the Server, User, and Password properties as appropriate.
  2. Set the Directory property to point to a directory where the session dictionary file will be created.
  3. Call the CreateSession() method.

When creating the session at run time, as shown below, it is not required to logon to the server. Though, if using the client/server model, the server must be running when this code is executed, otherwise an exception will be thrown with error ASKY_ERR (133), indicating the server is not active.

The sequences below represent the run time creation of the session dictionary in Delphi and C++.

Delphi Example


procedure Form1.CreateNewSession;

begin

try

CtSession1.Server := 'FAIRCOMS';

CtSession1.User := 'ADMIN';

CtSession1.Password := 'ADMIN';

{$IFDEF WIN32} // Windows path

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

{$ELSE} // Linux path

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

{$ENDIF}

CtSession1.CreateSession();

except

on E : ECtError do

Application.ShowException(E);

end;

end;

C++ Example


void Form1::CreateNewSession()

{

try

{

CtSession1->Server = "FAIRCOMS";

CtSession1->User = "ADMIN";

CtSession1->Password = "ADMIN";

#ifdef __WIN32__ // Windows path

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

#else // Linux path

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

#endif

CtSession1->CreateSession();

}

catch (ECtError& E)

{

Application->ShowException(&E);

}

}

TOCIndex