RAD Studio
ContentsIndex
PreviousUpNext
Iterating Through a Session's Database Components

You can use two session component properties, Databases and DatabaseCount, to cycle through all the active database components associated with a session. 

Databases is an array of all currently active database components associated with a session. DatabaseCount is the number of databases in that array. As connections are opened or closed during a session's life-span, the values of Databases and DatabaseCount change. For example, if a session's KeepConnections property is False and all database components are created as needed at runtime, each time a unique database is opened, DatabaseCount increases by one. Each time a unique database is closed, DatabaseCount decreases by one. If DatabaseCount is zero, there are no currently active database components for the session. 

The following example code sets the KeepConnection property of each active database in the default session to True:

var
  MaxDbCount: Integer;
begin
  with Session do
    if (DatabaseCount > 0) then
      for MaxDbCount := 0 to (DatabaseCount - 1) do
        Databases[MaxDbCount].KeepConnection := True;
end;

 

if (Session->DatabaseCount > 0)
  for (int MaxDbCount = 0; MaxDbCount < Session->DatabaseCount; MaxDbCount++)
    Session->Databases[MaxDbCount]->KeepConnection = true;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!