Solved

Detecting BDE presence !

Posted on 1997-05-15
8
768 Views
Last Modified: 2013-11-23
How can I detect if BDE is installed on a computer and if possible what version of BDE it is ?
0
Comment
Question by:sile
8 Comments
 
LVL 2

Expert Comment

by:javiertb
ID: 1336276
You can look for the [IDAPI] section in Win.Ini file by means of A TIniFile object and its methods (create, readsection,..) or any other way you like. If BDE is installed in the system, this section should contain a path to the IDAPI configuration file. Once you've checked that BDE is installed, you can get the version number using the method GetConfigParams of the Session object. You'll find more about this method and the Tinifile object in the on-line help.

0
 

Author Comment

by:sile
ID: 1336277
Can you give me some code on that ?

0
 
LVL 3

Expert Comment

by:sperling
ID: 1336278
javiertb's method won't work for 32-bit Windows. If you need this for  Delphi 2 or 3, use the code below. If this was what you needed, please reject javiertbs answer and allow me to submit this as an answer.

-----------------------
type
  TBDESYSVersion = packed record             { System Version Info }
    iVersion        : Word;                  { Engine version }
    iIntfLevel      : Word;                  { Client Interface level }
    dateVer         : LONGINT;               { Version date (Compile/Release) }
    timeVer         : LONGINT;               { Version time (Compile/Release) }
    szVersion       : array [0..19] of Char; { Version name (xxx.xxx.xxx.xxx) }
  end;

  TDBIGetSysVersion = function (var sysVersion : TBDESysVersion) : WORD; stdcall;

function GetBDEVersion(var Version : TBDESysVersion) : BOOLEAN;
var
  hLib             : INTEGER;
  DbiGetSysVersion : TDBIGetSysVersion;
  a                : ARRAY [0..MAX_PATH] OF CHAR;
  s                : STRING;
  hKey,
  valSize,
  valType          : INTEGER;
begin
// Initialize the return value. Assume BDE ain't installed
  Result := FALSE;

// Open the registry key containing BDE information, exit if failure
  if RegOpenKeyEx(HKEY_LOCAL_MACHINE, 'Software\Borland\Database Engine', 0, KEY_QUERY_VALUE, hKey) <> 0 then exit;

// Get the DLLPATH registry value, quit if failure or empty string
  valSize := SizeOf(a);
  if (RegQueryValueEx (hKey, 'DLLPATH', nil, @valType, @a, @valSize) <> 0)
  or (valSize=0) or (valType<>REG_SZ) then begin
    RegCloseKey(hKey);
    exit;
  end;

// Close the registry key.
  RegCloseKey(hKey);

// Make sure path ends with a \
  s := StrPas(a);
  if s[Length(s)]<>'\' then s := s + '\';

// Try loading the BDE DLL, exit if failure
  hLib := LoadLibrary(PChar(s+'IDAPI32.DLL'));
  if hLib=0 then exit;

// Try getting the address of the exported versioninfo procedure,
// exit if failure.
  @DbiGetSysVersion := GetProcAddress(hLib, 'DbiGetSysVersion');
  if @DbiGetSysVersion=nil then begin
    FreeLibrary(hLib);
    exit;
  end;

  try
    // If the call to DbiGetSysVersion returns OK (=0), Result is set to
    // true to indicate that the Version parameter contains valid info.
    Result := (DbiGetSysVersion (Version) = 0);
    FreeLibrary(hLib);
  except
    // If something happened, clean up and exit.
    on Exception do begin
      FreeLibrary(hLib);
    end;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  v       : TBDESysVersion;
  Major,
  Minor   : INTEGER;
begin
  if GetBDEVersion(v) then begin
    // BDE is Installed.
    Major := v.iVersion DIV 100;
    Minor := v.iVersion MOD 100;
    ShowMessage(Format('BDE Version %d.%.2d is installed', [Major, Minor]));
  end else begin
    // BDE not installed or corrupted.
    ShowMessage('BDE not found');
  end;
end;
---------------------


Regards,

Erik.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:sile
ID: 1336279
Would it be possible to acchieve this with less code * if I just need to detect if the BDE is present. Perhaps I should just read the registry for a key...Please include code


0
 
LVL 3

Expert Comment

by:sperling
ID: 1336280
function IsBDEInstalled : BOOLEAN;
var
  hKey   : INTEGER;
begin
  Result := RegOpenKeyEx(HKEY_LOCAL_MACHINE,
    'Software\Borland\Database Engine',
    0, KEY_QUERY_VALUE, hKey) = 0;
  if Result then RegCloseKey(hKey);
end;

Try this one. Simply checks whether the BDE registry key is present.

If this is what you need, please grade javiertb with an F allowing me to submit this as an answer instead of a comment.


Regards,

Erik.
0
 

Author Comment

by:sile
ID: 1336281
Could you please help me with this code. I can't get it to work.
I get an undeclared identifier msg. for RegOpenKeyEx, HKEY_LOCAL_MACHINE, KEY_QUERY_VALUE. I guess I should add something to the uses clause ?
0
 
LVL 3

Expert Comment

by:sperling
ID: 1336282
Hmmm. RegOpenKeyEx is declared in Windows.pas. If you're using Delphi 1, stick with javiertb's solution. If not, adding Windows to the uses clause should fix it.


Regards,

Erik.
0
 
LVL 1

Accepted Solution

by:
buemoh earned 40 total points
ID: 1336283
Dear sile,

The answers given before where correct, but a little bit unreadable. Here is some interesting smaller code which will help you, but NOTICE:
-------------------------------------------------
If you want to detect if BDE is installed and your program afterwards needs database-function you've to change the interface units of the Delphi database components to load all the BDE-IDAPI-DLLs after proofing of BDE installation and not static.

Borland loads the BDE STATIC !!!!!!!!!!!!!!!! - not VIRTUAL !!!!!!

You can also build a small program which proofs the BDE-installation and calls afterwards the program which uses databases.
------------------------------------------------------------------

Here is the small code, which supports both Delphi versions (1.x and 2.x):

uses
{$IFDEF Win32}
  Windows, Registry;
{$ELSE}
  WinProcs, SysUtils;
{$ENDIF Win32}

function IsBDEavailable : boolean;

{$IFDEF Ver80}

var
  p : PCHAR;
begin
  Result := false;
  p := StrAlloc( 256 );
  try
    GetProfileString( 'IDAPI', 'DLLPATH', '', p, 256 );
    Result := ( StrPas( p ) <> '' );
  finally
    StrDispose( p );
  end;

{$ELSE}

var
  Registry : tRegistry;
begin
  Result := false;
  Registry := tRegistry.create;
  try
    Registry.RootKey := HKEY_LOCAL_MACHINE;
    Result := Registry.KeyExists( 'SOFTWARE\BORLAND\Database Engine' );
  finally
    Registry.free;
  end;

{$ENDIF Ver80}

end;

-----------------------------

I hope, this is waht you want, but please read the NOTICE section!!

Bye

Hartwig

-----------------------------------------------------------
///\\\ Hartwig MOTAL ///\\\  e-mail: moh@bue.magwien.gv.at
 Weinberggasse 60/9/7, A-1190  Vienna/Austria/Europe

0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
code issue 8 156
Delphi : could not find program, '...exe' 2 193
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 73
Firemonkey android show image from resource ? 1 46
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question