Wednesday, June 25, 2008

Delphi, dbExpress And MySQL - Part 3

dbExpress: Delphi 6 Versus Delphi 7

When it comes to dbExpress, I have to agree with our very own Mr One Last Compile that it may sometimes be a good idea to skip a version of Delphi. Or let me slightly rephrase that: when it comes to dbExpress, you will get best results if you have only one version of the latest release of Delphi on your machine (either Delphi 6 or Delphi 7), but not both. Since I have both Delphi 6.02 and 7.01 on my machine, I encounter the following problem: the dbExpress drivers from Delphi 7 are not always downwards compatible with those of Delphi 6 (there have been issues with the InterBase driver), and those of Delphi 6 are certainly not upwards compatible with those of Delphi 7. While this doesn’t sound like a big issue, I will describe a few situations that have bitten me already.

On a machine with both Delphi 6 and 7, I can build a dbExpress application at design-time without problems, but when I hit F9 to run it from the Delphi 7 IDE, I suddenly get a dbExpress Error message Operation Not Supported (see Figure 4).

» Figure 4: dbExpress Error.

At design-time it works fine, showing all the data, and even at runtime (outside the IDE) everything is fine, but when started from the Delphi 7 IDE the project raises an exception the moment the SQLConnection component is activated. It actually took me a few hours to figure out that the problem was caused by the fact that my Delphi 7 application was looking for a dbExpress DLL and found it... in the Delphi6\bin directory (and not in the Delphi7\bin directory, since Delphi6\bin came first in the PATH).

And it gets worse. Some people, you know who you are, have been installing the dbExpress DLLs (like dbexpmys.dll and dbexpmysql.dll for MySQL) in the WinNT\System32 directory on their client machines. This seemed like a good idea, but with the changes in Delphi 7 this turns out to be a potential nightmare: the Delphi 6 versions of dbexpmys.dll and dbexpmysql.dll break all Delphi 7 applications, and while Delphi 7’s version of the dbExpress MySQL DLLs work fine with Delphi 6 applications, there will be problems with Delphi 7’s dbExpress InterBase DLLs and Delphi 6 applications (due to dbExpress field mappings that have changed from one version of Delphi to another: see the README for details). If you’re the only developer, you can recompile everything with Delphi 7, burn all ties with Delphi 6, and never look back. Until Delphi 8 ships (unless Borland learns something from this [Hah! Ed.]). A better solution may be to ensure that the dbExpress driver DLLs are only deployed in the application directory itself (and not in the system directory), which kinda defeats the idea of using DLLs in my view.

Finally, linking with the dbExpress driver unit instead of using the external DLL can be a solution in some cases (linking the dbExpress driver into your application), but not all. A serious quoting bug has been found in the dbExpress driver import unit for DB2 and Delphi 7, which renders this solution useless for DB2. So for now we just have to remain very cautious when we are deploying dbExpress and dbExpress applications.

No comments: