RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomConnection.DataSets Property

Lists the datasets currently using this connection component.

Pascal
property DataSets [Index: Integer]: TDataSet;
C++
__property TDataSet DataSets[int Index];

Use DataSets to access the datasets that are currently using the connection component. Depending on the TCustomConnection descendant, DataSets may include only the active datasets that use the connection component (as is the case with TDatabase and TSQLConnection), or it may list all datasets, regardless of whether they are active (as is the case with TADODatabase and DataSnap connection components TSOAPConnection). If DataSets includes only active datasets, its value changes when datasets are opened and closed.

Note: If a client dataset with an internal provider (for example TSQLClientDataSet or TBDEClientDataSet
) uses the connection component to connect to a database server, DataSets lists the internal dataset that the client dataset creates to access data, not the client dataset itself.  

Delphi Examples: 

 

{
The following code fragment illustrates how DataSets and
DataSetCount can be used to ensure that an action is taken
for every open dataset.  Assign CheckButtonActive as the
AfterClose and AfterOpen event handlers for TClientDataSet1.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
begin
  if not RemoteServer1.Connected then
    RemoteServer1.Connected := True;
  ClientDataSet1.Close;
  with RemoteServer1 do
  begin
    for I := 0 to DataSetCount - 1 do
      DataSets[I].EnableControls;
  end;
  ClientDataSet1.Open;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  I: Integer;
begin
  ClientDataSet1.Close;
  RemoteServer1.Connected := False;
  with RemoteServer1 do
  begin
    for I := 0 to DataSetCount - 1 do
      DataSets[I].DisableControls;
  end;
end;

procedure TForm1.CheckButtonActive(DataSet: TDataSet);
begin
  Button1.Enabled := not ClientDataSet1.Active;
  Button2.Enabled := ClientDataSet1.Active;
  Button3.Enabled := ClientDataSet1.Active;
end;

 

DataSetCount 

Active 

Working with Associated Datasets

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!