RAD Studio |  |

Activating a Session
See Also
Collapse All

Active is a Boolean property that determines if database and dataset components associated with a session are open. You can use this property to read the current state of a session's database and dataset connections, or to change it. If Active is False (the default), all databases and datasets associated with the session are closed. If True, databases and datasets are open.

A session is activated when it is first created, and subsequently, whenever its Active property is changed to True from False (for example, when a database or dataset is associated with a session is opened and there are currently no other open databases or datasets). Setting Active to True triggers a session's OnStartup event, registers the paradox directory locations. with the BDE, and registers the ConfigMode property, which determines what BDE aliases are available within the session. You can write an OnStartup event handler to initialize the NetFileDir, PrivateDir, and ConfigMode properties before they are registered with the BDE, or to perform other specific session start-up activities.

Once a session is active, you can open its database connections by calling the OpenDatabase method.

For session components you place in a data module or form, setting Active to False when there are open databases or datasets closes them. At runtime, closing databases and datasets may trigger events associated with them.

Note: You cannot set Active to False for the default session at design time. While you can close the default session at runtime, it is not recommended.
You can also use a session's Open and Close methods to activate or deactivate sessions other than the default session at runtime. For example, the following single line of code closes all open databases and datasets for a session:
Copy Code

    Session1.Close;

Copy Code

    Session1->Close();

This code sets Session1's Active property to False. When a session's Active property is False, any subsequent attempt by the application to open a database or dataset resets Active to True and calls the session's OnStartup event handler if it exists. You can also explicitly code session reactivation at runtime. The following code reactivates Session1:

Copy Code

    Session1.Open;

Copy Code

    Session1->Open();

Note: If a session is active you can also open and close individual database connections. For more information, see Closing database connections.
See Also

Creating Additional Sessions

Specifying Default Database Connection Behavior

Managing Database Connections

Working with BDE Aliases

Specifying Paradox Directory Locations

Working with Password Protected Paradox Tables

Managing Multiple Sessions

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!