?
Solved

Detecting BDE presence !

Posted on 1997-05-15
8
Medium Priority
?
787 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

770 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