Delphi 2007 Handbook




Essential Pascal




social web book








April 10, 2006

Delphi 2006 and WinForms in .NET 2.0

Delphi 2006 can be used to write .NET 2.0 applications... by using the command line compiler.

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).





 

7 Comments

Delphi 2006 and WinForms in .NET 2.0 

 The problem is other. ¿ can i install visual studio 
2005 in the same machine that i install delphi 2006  
without problems in delphi 2006 ? This is the real 
problem. In previous version exist problems.  
Comment by vicente [avmm2004@yahoo.es] on April 10, 19:17

Different version on the same PC 

Vicente: I always had several different version of 
Delphi installed on the same PC and never had 
problems. A few years ago I had Delphi 1, 3, 4, 5 and 
6 installed on the same PC. Then I had 5, 6 and 7. 
Now I have 7, 2005 and 2006.

A couple of advices:

1) Install them "in order". Installers should not 
change newer file now, but better to err on the safe 
side.
2) Don't mix SKUs, i.e. a Pro with an Enterprise, 
some common features may be deleted or changed from a 
lower SKU.
Comment by Luigi D. Sandon on April 11, 13:34

Delphi 2006 and WinForms in .NET 2.0 

i install both Delphi 2006 (Delphi for Win32 only) 
and Visual Studio 2005 Pro, it works fine. but if 
you select to install C# Builder, the problems come. 
and read this post, i finally figure out this 
problem. thanks Mr. marco cantu!
Comment by goyo on April 17, 05:28

Delphi 2006 and WinForms in .NET 2.0 

 To All:
        By referance this info , I create a product
called "Pocket Go!! for BDS2006" .

Now , I can develop all kinds of DotNet application
(DotNet1.X / DotNet2.X/CF1.X/CF2.X), Thanks a lot.

                             from  : atomlin
                             E-Mail: ctom3464@hotmail.com

Comment by Everything is fine on September 5, 11:14

Delphi 2006 and WinForms in .NET 2.0 

 Hi !

I replicated yours steps, including System.Io.Ports 
namespace and the code:

procedure TWinForm.btn1_Click(sender: System.Object; 
e: System.EventArgs);
var
  a : SerialPort;
begin

  btn1.FlatStyle := FlatStyle.Flat;

  a := SerialPort.Create;

  lbl1.Text := a.PortName;

end; 

..and works !

Thank's for the help ! 
Comment by Wilson A Augusto on February 19, 19:41

Delphi 2006 and WinForms in .NET 2.0 

 Hi !

How I convert my .exe .NET 2.0 to Compact Framework 
2.0 ?

What is the .pub file ?

Thank's

wilsonaaugusto@itelefonica.com.br
Comment by Wilson A Augusto on March 21, 18:32

use .net 2.0 component in delphi 2006 

hi
how i use a .net v2.0 component in delphi 2006
//dhelphi 2006 use .netframework 1.1
Comment by micy on June 1, 08:41


Post Your Comment

Click here for posting your feedback to this blog.

There are currently 0 pending (unapproved) messages.