Solved

Detecting BDE presence !

Posted on 1997-05-15
8
779 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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