Creating Additional Sessions
Go Up to Managing database sessions Index
You can create sessions to supplement the default session. At design time, you can place additional sessions on a data module (or form), set their properties in the Object Inspector, write event handlers for them, and write code that calls their methods. You can also create sessions, set their properties, and call their methods at run time.
To enable dynamic creation of a session component at run time
- Declare a TSession variable.
- Instantiate a new session by calling the Create method. The constructor sets up an empty list of database components for the session, sets the KeepConnections property to True, and adds the session to the list of sessions maintained by the application's session list component.
- Set the SessionName property for the new session to a unique name. This property is used to associate database components with the session. For more information about the SessionName property, see Naming a Session.
- Activate the session and optionally adjust its properties.
You can also create and open sessions using the OpenSession method of TSessionList. Using OpenSession is safer than calling Create, because OpenSession only creates a session if it does not already exist. For information about OpenSession, see Managing Multiple Sessions.