The Garbled PATH Variable

Some of you might have already been bitten by this one: After installing a new Delphi version you end up with a garbled PATH variable, simply because the installer tries to extend this variable over some limit. I was not able to find enough reliable information to name this limit, but it might be something about 2000 characters, but this might as well depend on the underlying operating system.

During the setup of a new system with lots of older Delphi versions I decided to write a simple program that uses environment variables to compress the PATH variable so that hopefully it fits when installing the next Delphi version. Continue reading “The Garbled PATH Variable”

Poor Man’s CSV Export

Recently I came to the point where I had to export the tables of a database as CSV files. While in FireDAC there is TFDDataMove, I wasn’t able to use it as I encountered a bug  in that component that rendered the output useless. (The bug has been fixed by Dmitry the day after I mentioned it, but is not publicly available yet.)

So I wondered how such a simple CSV export can be done with things available in Delphi. Well, here it is: Continue reading “Poor Man’s CSV Export”

When, What, Why!

A common pattern seen in Delphi code is the “code inside an event handler” syndrome. Lines and lines of code are placed inside an event handler. Not enough, these event handlers are often called directly from other places in the code – just because the code inside it needs to be executed. Take that as a big sign of code smell!

You know what? The event handler is not the right place for that code.

Extract it into a separate method – or probably more of them. Name those methods so that the name describes what the code executed is supposed to do. (It is probably not doing that, but that is a case for debugging.)

You can give some extended description in a comment to the method. If you have Document Insight (you should have the Express version with any recent Delphi), use it to display this comment wherever you hover the mouse over that method name.

Place the method calls into the event handlers. May be, you can write a little comment that explains why you are calling these methods. Don’t reword the method names here.

Remember: The event handler names tell you when that code is executed, the method names tell you what is executed and the comments tell you why it is executed.

BTW: Don’t try to be clever and rename the event handler so that its name resembles the what. You will have a hard time to find out the when! It would only be stored in the event wiring of the DFM and needs the Object Inspector to see it. It only makes the code harder to read. Keep the event handler names as given when possible. In case it is wired to multiple events, name it according to its usage (like DataSetsAfterPost), not its purpose.

18 Years of Delphi Programming

Some weeks after I got my Delphi 1 I had some contract work for a CAD/CAM system at a company located in my home town. After discussing a specific problem with their chief programmer (he was on C++) for the whole morning I was not able to convince him that my proposed solution will work.

During lunch break I went home, started Delphi and just wrote a prototype for proof. When I came back only about an hour after I left and showed him the working sample, he couldn’t believe it – always trying to find out how I did manage to cheat.

A few months later he quit…

Happy Birthday Delphi!

DataSnap in the Cloud

Last weekend I spoke at the Delphi Tage in Heidelberg about DataSnap In The Cloud and I promised to provide the referenced data for download. So here it is:

DataSnap in the Cloud (PDF)

The slides from the presentation. I omitted those slides serving transition effects only.

FishFacts (Project)

The modified FishFacts project. The console application project is called FishFactsServer.  It contains the changes to make it work with SQL Database in Azure as well as the patched Data.DBXMSSQLMetaDataReader.pas (XE2) to make it work with SQL (Azure) Database.

Azure Cloud Service

The Azure Cloud Services Project. You have to copy the FishFactsServer.exe into the WorkerRole folder after compilation and before making the package.

DbDemos SQL Script

SQL Script for DbDemos Database. Executing this script in SQL Managment Studio will create and populate the complete dbdemos database in a format suitable for SQL (Azure) Database.