The following code fragment illustrates how DataSets and DataSetCount can be used to ensure that an action is taken for every open dataset that is a table. After that all open datasets will be closed.
var I: Integer; begin with PSQLDatabase1 do begin while DataSetCount <> 0 do begin if DataSets[0] is TPSQLTable then begin // Some code end; DataSets[0].Active := False; end; end; end;