Search code examples
delphidelphi-xe2adovcl

List all queries connected through ado connection


I have application that has ADO connection on main form and several plugins that have ADO queries which I connect to this main connection. One problem is that I can't properly design those plugins without their personal connection which becomes messy when I connect plugins to main app. One plugin has plenty of queries.

I can use ConnectionObject to pass plugin's queries through main connection, but this is non-convenient for me, because when main connection needs to reconnect, I can't automatically reconnect all the queries. So I have to reassign those plugins' Connection property to main connection after plugin creation.

I know that one can list all active queries using ADOConnection's DataSets property. But what property should I use if I want to list both active and inactive DataSets? The IDE lists them automatically in designer, so I think there should be a generic way to do this.


Solution

  • Perhaps documentation regarding TADOConnection.DataSets which can be found here has confused you.

    It says:

    Use DataSets to access active datasets associated with a connection component.

    This might leed to thinking that DataSets keeps only active datasets which is not the case. To test this, just put one TADOConnection and one TADOQuery component on a form and set up TADOQuery.Connection to the instance of your connection, for example ADOConnection1.

    To test that DataSets property keeps also inactive datasets you might use this code:

    procedure TForm1.FormCreate(Sender: TObject);
    var
      i: Integer;
    begin
      for i := 0 to ADOConnection1.DataSetCount - 1 do
      begin
        if not ADOConnection1.DataSets[i].Active then
          ShowMessage('Inactive dataset!');
      end;
    end;