1 2 unit Unit1; 3 4 interface 5 6 uses 7 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 8 Dialogs, StdCtrls,Registry; 9 10 type 11 TForm1 = class(TForm) 12 Button1: TButton; 13 ListBox1: TListBox; 14 Button2: TButton; 15 procedure Button1Click(Sender: TObject); 16 procedure Button2Click(Sender: TObject); 17 private 18 { Private declarations } 19 public 20 { Public declarations } 21 procedure GetDataSourceNames(System: Boolean); 22 end; 23 24 var 25 Form1: TForm1; 26 27 implementation 28 29 {$R *.dfm} 30 31 procedure TForm1.GetDataSourceNames(System: Boolean); 32 var 33 reg: TRegistry; 34 begin 35 ListBox1.Items.Clear; 36 37 reg := TRegistry.Create; 38 try 39 if System then 40 reg.RootKey := HKEY_LOCAL_MACHINE 41 else 42 reg.RootKey := HKEY_CURRENT_USER; 43 44 if reg.OpenKey('\Software\ODBC\ODBC.INI\ODBC Data Sources', False) then 45 begin 46 reg.GetValueNames(ListBox1.Items); 47 end; 48 49 finally 50 reg.CloseKey; 51 FreeAndNil(reg); 52 end; 53 end; 54 55 procedure TForm1.Button1Click(Sender: TObject); 56 begin 57 //System DSNs 58 GetDataSourceNames(True); 59 end; 60 61 62 procedure TForm1.Button2Click(Sender: TObject); 63 begin 64 //User DSNs 65 GetDataSourceNames(False); 66 end; 67 68 end. 69