如何列出本机支持的数据驱动列表?

解决方案 »

  1.   

    BDE 用Session
    ODBC 用注册表
      

  2.   

    1BDE, 
      use DbTables  Session.GetDriverNames(CmbAccAlias.Items);2ODBC, 刚好昨天写了一个 procedure ListODBCDSN(AList: TStrings; AFlag: Integer);  AFlag 0:用户DSN, 1:系统DSN 2: 所有DSN
    var
      Reg: TRegistry;
      UserList, SysList: TStringList;
    begin
      if AList = nil then Exit;
      AList.Clear;
      Reg := TRegistry.Create;
      try
        case AFlag of
          0: begin
            Reg.RootKey := HKEY_CURRENT_USER;
            Reg.OpenKey('Software\ODBC\ODBC.INI', False);
            Reg.GetKeyNames(AList);
            Reg.CloseKey;
          end;
          1: begin
            Reg.RootKey := HKEY_LOCAL_MACHINE;
            Reg.OpenKey('Software\ODBC\ODBC.INI', False);
            Reg.GetKeyNames(AList);
            Reg.CloseKey;
          end;
          2: begin
            UserList := TStringList.Create;
            SysList := TStringList.Create;
            try
              ListODBCDSN(UserList, 0);
              ListODBCDSN(SysList, 1);
              UserList.AddStrings(SysList);
              UserList.Sort;
              AList.Assign(UserList);
            finally
              SysList.Free;
              UserList.Free;
            end;      end;
        end;
      finally
        Reg.Free;
      end;
    end;