Yesterday I played with the DCCIL
command line compiler and noticed an interesting compiler switch called clrversion
. And yes, it does exactly what its name suggest, it loads another CLR version of .NET, rather than the default one "v1.1.4322".
Therefore, I took out my .NET 2.0 installer and installed it in my BDS 2006 test VM. It never saw the version 2.0 of .NET before ;-) So far so good. I started the Developer Studio 2006 and created a new, simple console application. Thanks to the .NET SDK from my Visual Studio 2005 VM I found a simple test case rather fast.
Console applications for the MS.NET Framework 1.1 do not support changing the background color through System.Console.BackgroundColor
. So it does not compile within the Developer Studio against the .NET 1.1.
Okay, create a .dpr file, copy this "complex" lines into it and save it into a folder on your disk with the name SimpleSampleNET2
. Enter following command line into your command line (will not work yet, but never mind that now; not the path for the -NS switch!): dccil -CC -NSC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 --clrversion:v2.0.50727 --no-config SimpleSampleNET2.dpr
You'll see the Delphi compiler loading the .NET 2.0 framework. The success is announced in line 3: .NET Framework v2.0.50727 loaded
. Next it'll load some of the assemblies needed and create the "dcpil" files as needed. However, it stops with an error when trying to include the Borland System unit: SimpleSampleNET2.dpr(1) Fatal: F1026 File not found: 'Borland.Delphi.System.dcuil'
Well, go to $(BDS)\source\dotNet\rtl and copy the file Borland.Delphi.System.pas
to your application path. Now you simply need to recompile the system unit for .NET 2.0, using the following command line: 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
. Never mind the warnings and that single hint there.
Now, compile your little application again: dccil -CC -NSC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 --clrversion:v2.0.50727 --no-config SimpleSampleNET2.dpr
Now, in the command line, start your little application. If you do not have "Blue" as background color already, it should be changed now, as we have done just that in our code. It works! It is a .NET 2.0 application written and compiled with the Delphi 2006 .NET compiler. Just to be sure, copy that little application on a computer that only has .NET 2.0 installed (not .NET 1.1) and test it. It'll work just the same there.
Take it from here and have fun!
On Request I have bundled a small package for you (ConsoleApplication.zip 8KB
). It contains:
It does not
contain the Borland.Delphi.System.pas
file! Copy that from your installation path as instructed above prior to running make.bat.