怎么知道当前运行的程序中间活动的打开的数据库控件有那些?因为数据控件都在datamodule中,应用的窗体关闭后,数据库控件依然处于打开的状态,很多时候控件多了,没有关闭完,很容易产生错误.

解决方案 »

  1.   

    for i:=0 to form1.ComponentCount-1 do
      begin
        if form1.Components[i] is tadoquery then
          if form1.Components[i].Active=false then
          showmessage('false')
          else
          showmessage('true');
        else
        showmessage('a');
      end;
    end;
    我想在窗体关闭的代码中加入这个代码,来观察是否有那些ado控件还没有关闭,但是用form1.components[i].这个方式,但是active这个属性没有了.
      

  2.   

    // 显示你未关闭的ADO。参数 AdodsParent:你要查看的FORM
    uses TypInfo, Math;
    procedure ShowOpenedAdoDs(AdodsParent:TForm);
    var i:integer;
        v:Variant;
        p:ppropinfo;
        strSate:string;
    begin
        with AdodsParent do
        begin
        for i:=0 to ComponentCount-1 do
        begin
            begin
              p:=nil;
              p:=GetPropInfo(AdodsParent.Components[i],'Active');
              if p<>nil then
              begin
              v:=GetPropValue(Components[i],'Active');
                 if Components[i] is TCustomADODataSet then
                    showmessage(TCustomADODataSet(Components[i]).Name);
              end;
            end;
        end;
        end;
    end;