Solved

Detecting BDE presence !

Posted on 1997-05-15
8
749 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
Comment Utility
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
Comment Utility
Can you give me some code on that ?

0
 
LVL 3

Expert Comment

by:sperling
Comment Utility
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
 

Author Comment

by:sile
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:sperling
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now