Tuesday, February 20, 2007

I have used compilers and languages for a long time and it is the first time that I have encountered a compiler (Delphi 2006) that actually throws away public types from not only .Net executables but also packages.

Discarding from an executable is kind of understandable because Borland simply extends the same assumption they used in Delphi.W32 to Delphi.Net, admittedly very foolishly and ignorantly. Borland probably does not realise that one can load an executable assembly in much the same way as a DLL assembly.

To see this, you can get the IDE wizard to generate say a VCL.Net Form application. Anywhere in a pas file, create a type in the interface section and build it.

Then examine the final product with a Lutz Reflector and you will find that Delphi has discarded this type. I suspect that Borland only discards the IL metadata of this type, the one that the Reflector and System.Reflection depends on but keeping them in Delphi's metadata.

In other word, Delphi.Net is producing dll for Borland environment only.

To retain this type, you need to create a dummy variable of this type in the implementation section. Now you will see this type being retained.

What is insane of Borland is to discard public types from a package? Public type in a DLL is meant to be used by another DLL or executable and so how could Delphi know that no one is going to reference this type and is safe to discard them?

My discovery has proved that Borland has made very unsafe judgment bordering on insane.