About the author
Delphi is the only .NET language in the world that allows you to call any CLR routines without using COM Interop or COM registration. This is achieved by using the UNSAFECODE directive in a Library, together with the exports clause. This feature, is also known as unmanaged exports.
Principal Architect, .NET products, Borland Software Corporation, Allen Bauer, discussed this in his blog, “Wither go the RTL”, but gave no examples of how it can be done.
With Delphi 7 and Delphi 8, moving to the managed world that is .NET is a no-brainer. You can move your applications slowly, by writing bridging DLLs / libraries in Delphi 8, and calling it from your Delphi 7. Of course, if you're not a Delphi user, you still can call the Delphi 8 libraries using your favourite language. So, it's one reason some of you might want to rush out now to get Delphi 8. After all, Delphi 8 includes Delphi 7. Delphi 8 Architect includes 12 CDs, in 4 maroon jackets.
Note: It is an error to use the exports clause without {$UNSAFECODE ON}.
Delphi 7 code (Win32)program CallCLR;{$APPTYPE CONSOLE}procedure HelloWorld; stdcall; external 'D8CLRLIB.DLL' name 'HelloWorld';begin WriteLn('Hello from Win32 world...'); HelloWorld;end.
Delphi 8 code (.NET)library D8CLRLIB;{$UNSAFECODE ON}{%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\v1.1.4322\system.windows.forms.dll'}
uses System.Windows.Forms;
procedure HelloWorld;begin MessageBox.Show('Hello from managed world!!!') Console.WriteLine('Hello console, I''m from the managed world!');end;
exports HelloWorld;
beginend.
Download the source code and binaries here, which includes a more complete example.