TechTricks
Technical answers from the trenches 
 
 
 
 

     
   
More Informative BDE Errors
 
   
 Posted: 01 May 2001
 
   
 
 Applies to: Delphi 4.0 and later
 
   
 
Audience: Intermediate
 
       
   

Introduction

If you create applications using the Borland Database Engine, you've probably seen exceptions raised by the BDE. For example: "Key violation," "Table does not exist," and so on. While these messages are accurate, they're not entirely helpful, for they rarely contain enough information to be completely useful for troubleshooting. If you're dealing with off-site clients, it can be frustrating to determine the next course of action.

You may not, however, be aware that EDBEngineError is a subclass of the Exception class, one with additional functionality not provided in the base class.

Specifically, EDBEngineError errors are lists of other error messages. You can use this to provide more complete information when problems occur, as shown in the following code sample:

var
   strErrors : String; // used for BDE errors
begin
try
   doProcess;
except
   on E:EDBEngineError do
   begin
      strErrors := 'A database engine error occurred.' + #10 +
                   'Details:' + #10#10;

      for siCounter := 0 to ErrorCount - 1 do
         strErrors := strErrors +
            '(' + IntToStr( Errors[ siCounter ].ErrorCode ) +
            ') ' + Errors[ siCounter ].Message + #10;

         application.MessageBox( pchar( strErrors ),
            'Database Error', MB_ICONHAND + MB_OK );
   end;

This example uses the EDBEngineError's errorCount() method to determine the number of errors on BDE's stack of messages and then adds each message to strErrors. When the process is complete, the full message is displayed to the user.

If you're familiar with the BDE.INT file provided in the DOC\ directory of Professional and Enterprise editions of Delphi, you may wish to replace the IntToStr() calls with IntToHex(). Doing so makes it easier to cross-reference unfamiliar error codes with the ones provided in the BDE.INT file.

The sample files provided in the DEMOS\DB\DBERRORS\ directory contains additional ideas along these lines.

 

       

Top

Feedback About Paradox Delphi Assorted Web Stuff
 
 
Copyright © 2000-2004, techtricks.com; All Rights Reserved.
Acknowledgements, Disclaimers, Terms and Conditions.
Article last updated on 31 May 2003

 

Other Sites: Paradox, Delphi, Perl, Web Stuff, and More


 

[- End -]