Recent

Author Topic: List ODBC data sources in combobox  (Read 3058 times)

mm_coder

  • Jr. Member
  • **
  • Posts: 50
List ODBC data sources in combobox
« on: March 13, 2017, 08:37:50 pm »
Porting a vb6 application to Lazarus.

I need to know how to display the list of installed ODBC drivers in a combo box for
the user to select for application setup.

Windows platform

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: List ODBC data sources in combobox
« Reply #1 on: March 13, 2017, 09:25:06 pm »
Something like:
Code: Pascal  [Select][+][-]
  1. // add registry to the uses clause
  2. procedure TForm1.FormCreate(Sender: TObject);
  3. var
  4.   Reg:TRegistry;
  5. begin
  6.  Reg := TRegistry.Create;
  7.  try
  8.    Reg.RootKey:= HKEY_LOCAL_MACHINE;
  9.    Reg.OpenKey('Software\ODBC\ODBCINST.INI\ODBC Drivers',False);
  10.    Reg.GetValueNames(Combobox1.Items);
  11.  finally
  12.    Reg.Free;
  13.  end;
  14. end;
  15.  
« Last Edit: March 13, 2017, 09:49:56 pm by Thaddy »
Specialize a type, not a var.

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: List ODBC data sources in combobox
« Reply #2 on: March 13, 2017, 10:19:43 pm »
Windows platform
Also note that in case you are using SQL Server (small chance  ofc :D) Windows has a new ODBC driver that requires a separate download and installation.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

mm_coder

  • Jr. Member
  • **
  • Posts: 50
Re: List ODBC data sources in combobox
« Reply #3 on: March 14, 2017, 12:14:08 am »
Working perfectly. Thanks for taking the time.

Still getting used to the pascal way.
Thanks

 

TinyPortal © 2005-2018