How to check if the BDE is installed #28

Answer 1

Your application may use several approaches to databases depending on what is installed on the user's computer. Before you use the BDE you may want to check if it has been installed. If not then you may either ask the user to do so first, else just use something else. The function below (roughly a couple lines of code) checks for BDE presence.

uses
  Bde;

function BDEInstalled: Boolean;
begin
  Result := (dbiInit(nil) = 0);
end;

A version of this function is available in the DelphiDabbler Code Snippets Database as CheckBDEInstalled.

Answer 2

function isbdepresent: boolean;
var
  IdapiPath: array[0..255] of Char;
  IdapiHandle: THandle;
begin
  result := false;
  GetProfileString('IDAPI', 'DLLPath', 'C:\', IdapiPath, 255);
  {next lines isolates the first directory path from the IdapiPath in
  case there are more}
  if Pos(';', StrPas(IdapiPath)) <> 0 then
  begin
    StrPCopy(
    	IdapiPath,
    	Copy(StrPas(IdapiPath), 1, Pred(Pos(';', StrPas(IdapiPath))))
    );
  end;
  IdapiHandle := LoadLibrary(StrCat(IdapiPath, '\IDAPI01.DLL'));
  if IdapiHandle < HINSTANCE_ERROR then
    result := false
    {IDAPI is not present on this system}
  else
  begin
    FreeLibrary(IdapiHandle);
    result := true;
    {IDAPI is present on this system}
  end;
end;

Tip by Brian Bushay, formerly published on the defunct Delphi Pool web site.

Answer 3

Try to check the registry for the presence of the BDE:

with TRegistry.create do
  try
    Rootkey := HKEY_LOCAL_MACHINE;
    OpenKey('SOFTWARE\BORLAND\DATABASE ENGINE', false);
    CFGFile := ReadString('CONFIGFILE01');
  finally
    Free;
  end;
end;

The BDE is installed if CFGFile is not ''.

Tip based on anonymous code formerly published on the defunct Delphi Pool web site.

Author: Various
Added: 2007/06/02
Last updated: 2013/10/12