Holger's Thoughts on Delphi

Wednesday, September 20, 2006

ECO: Code generation in BDS 2006 and Delphi .NET

Okay, you all know by now, I am a huge fan of ECO. Today I found out though that if you keep making modifications to your model and constantly generate code for Delphi .NET that the code generator will generate code that does simply not compile.

Firstly, deactivate the option "One file per class" for the code generation in Delphi (see screenshot) in case you enabled it. It is set to "off" by default when you install BDS.

You get to this dialog using "Tools / Options...". There are two issues if you leave it checked:
  • uses-clause: The uses clause is not being generated correctly if you e.g. have a method that returns another class which resides in another unit. You will have to add the references yourself.
  • duplicate names: if an association(-end) has the same name as a class you get type-conflicts and will have to use the full name and thus edit the code manually
Secondly, "begin"/"end" blocks are preceded by multiple empty lines. With every code generation invocation another empty line is being added.
Finally - and this is the most annoying - Uml-tags will be generated everytime you invoke the code generator and thus the code becomes incompilable as well.

I wrote a simple command-line tool, which automatically makes the necessary changes for the last two cases. The uses-clause and duplicate-names issue can be neglected as you can set the options to circumvent it.

Be aware that this tools comes without any guarantee or liability. Use it at your own risk.

You can download it from CodeCentral.


Post a Comment

<< Home