用BDE中的TSession组件可以用如下方法获得本地所有ODBC数据源名
Session1.GetAliasNames(Listbox1.items)
但是这样的话,程序发布的时候,需要打包BDE,程序本身很小,一打包就会变很大了,有没有什么其他方法可以获得本地所有数据源名啊,ADO可以吗?API怎么实现?可以写一些关键代码给小弟吗?谢谢了.

解决方案 »

  1.   

    直接用ado开发吧,在当前的计算机系统上发布和部署都是比较方便的
      

  2.   

    ...Extract the ODBC System Data Sources? 
    uses
      Registry;procedure TForm1.Button1Click(Sender: TObject);
    var
      n: Integer;
      List: TStringList;
      Reg: TRegistry;
    begin
      Reg := TRegistry.Create;
      try
        Reg.RootKey   := HKEY_CURRENT_USER;
        Reg.LazyWrite := False;
        Reg.OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources', False);
        List := TStringList.Create;
        Reg.GetValueNames(List);
        ListBox1.Clear;
        for n := 0 to List.Count - 1 do
          ListBox1.Items.Add(List.Strings[n]);
        Reg.CloseKey;
      finally
        Reg.Free;
      end;
    end;
      

  3.   

    aiirii大哥,这样我已经想到了,但是用Session1.GetAliasNames(Listbox1.items)的话,还能取得数据库别名,用读注册表的方法不可以,有什么更好的方法吗?如果没有了就结贴给分了.
      

  4.   

    An application can call SQLDataSources multiple times to retrieve all data source names. The Driver Manager retrieves this information from the system information. When there are no more data source names, the Driver Manager returns SQL_NO_DATA. If SQLDataSources is called with SQL_FETCH_NEXT immediately after it returns SQL_NO_DATA, it will return the first data source name. For information about how an application uses the information returned by SQLDataSources, see Choosing a Data Source or Driver.If SQL_FETCH_NEXT is passed to SQLDataSources the very first time it is called, it will return the first data source name.The driver determines how data source names are mapped to actual data sources.
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcsqldatasources.asp