?
Solved

Detecting BDE presence !

Posted on 1997-05-15
8
Medium Priority
?
801 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
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 160 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 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