In a recent blog post, Daniel Wischnewski shows how to compile a Delphi application for .NET 2.0. The trick is to use (from the command line compiler, not from the IDE) the --clrversion flag. He shows that you can compile a .NET 2.0 console application (using a specific 2.0 feature, the console background color) with this command:

dccil -CC 
-NSC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
--clrversion:v2.0.50727
--no-config
SimpleSampleNET2.dpr

The only extra operation you have to do the first time is to copy to the project folder the source code file Borland.Delphi.System.pas and compile it with the following command:

dccil -CC 
-NSC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
--clrversion:v2.0.50727
--no-config
-Q -M -y -Z -$D-
Borland.Delphi.System.pas

Now, before you think I'm only quoting his work in my blog post, I've easily replicated Daniel's steps, but gone one step forward. I've used Delphi 2006 to create a new Delphi for .NET WinForms application, added to it code specific to version 2.0 of WInForms, and compiled it with a similar command line call.

In my extra code I've added the flat style to a button and used a new .NET 2.0 control to play a sound. This is my code:

procedure TWinForm3.ButtonClick(sender: TObject; e: System.EventArgs);
var
  sndPlayer: SoundPlayer;
begin
  Button1.FlatStyle := FlatStyle.Flat;
  
  sndPlayer := SoundPlayer.Create;
  sndPlayer.SoundLocation := 'C:\Program Files\Messenger\type.Wav';
  sndPlayer.LoadAsync;
  if sndPlayer.IsLoadCompleted then
    sndPlayer.Play;
end;

Now you cannot compile this code with the Delphi 2006 IDE, as some of the features are specific to .NET 2.0. But you can compile it with the following command line, similar to the previous ones but with references to the assemblies used:


dccil -CC 
-NSC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
--clrversion:v2.0.50727
--no-config
projform20.dpr
-luC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
-luC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll

Of course, with no help from the designer, no IDE-based compilation, and no proper Code Insight (although it might be possible to turn these on), building WinForms 2.0 applications in Delphi 2006 is far from a great experience. However, if you want to experiment with some of the new components and properties, while you wait for Highlander (next version of Delphi), and don't care to install Visual Studio, this might be an interesting option. This also speaks in favor of the flexibility of the BDS IDE.

(Please, no IDE wars on this blog entry, I've had quite enough in the 34 talkback messages posted here).