Activating a Session
Go Up to Managing database sessions Index
Active is a Boolean property that determines whether database and dataset components associated with a session are open. You can use this property to read the current state of a session 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 associated with a session is opened and there are currently no other open databases or datasets). Setting Active to True triggers a session Bde.DBTables.TSession.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 run time, closing databases and datasets may trigger events associated with them.
You can also use a session Open and Close methods to activate or deactivate sessions other than the default session at run time. For example, the following single line of code closes all open databases and datasets for a session:
This code sets Session1 Active property to False. When a session Active property is False, any subsequent attempt by the application to open a database or dataset resets Active to True and calls the session OnStartup event handler, if it exists. You can also explicitly code session reactivation at run time. The following code reactivates Session1: