unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Registry;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure GetDataSourceNames(System: Boolean);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.GetDataSourceNames(System: Boolean);
var
reg: TRegistry;
begin
ListBox1.Items.Clear;
reg := TRegistry.Create;
try
if System then
reg.RootKey := HKEY_LOCAL_MACHINE
else
reg.RootKey := HKEY_CURRENT_USER;
if reg.OpenKey('\Software\ODBC\ODBC.INI\ODBC Data Sources', False) then
begin
reg.GetValueNames(ListBox1.Items);
end;
finally
reg.CloseKey;
FreeAndNil(reg);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//System DSNs
GetDataSourceNames(True);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//User DSNs
GetDataSourceNames(False);
end;
end.