There has been an interesting discussion on the non-tech newsgroup that started with a request to support the so-called "mixed-mode" in the Delphi .NET compiler. Mixed-mode is a way to let you mix in the same executable (or compilation unit) managed and unmanaged code. The most relavant example of this appraoch is Microsoft's C++/CLI, introduced in some detail in this book chapter, that supercedes the earlier Managed C++.

From the C++ language perspective I think this is an interesting appraoch. Since the C++ language is really incompatible with the .NET model (or CLI, Common Language Infrastructure model) the only options are: (i) rewrite everything in C# (similar syntax, but very different language) (ii) extend the language providing new keywords and constructs. If you have a lot of code solution (ii) looks interesting. Of course, the existing C++ code will compiled to unmanaged code, while the new code you write can take full advantage of .NET.

Enter Delphi. In Delphi the native object model matches the .NET model almost exactly. This is why you can take existing Delphi Win32 code (unless you use low-level techniques, pointers, and the like) and recompile it for .NET, making it "native" and "managed". Like you were actually rewriting in C#. In Delphi you get (i) and (ii) at the same time, without having to change your class declarations or memory allocations, like C++/Cli requires you to do if you want to take advantage of .NET. This is why I find Delphi / Delphi .NET appraoch way better than the C++/CLI appraoch. Granted, the same could not be done with C++ as a language, and might be interesting for C++Builder or any future Borland C++ compiler willing to support .NET. But for Delphi, I think this wuold have been a mistake.

Mixing code. It is true that you might need to mix Win32 (native) code and .NET (managed) code. But do you really need to use a single executable? One area in which Delphi for .NET shines is in providing both a way to call Win32 code from .NET applications (P/Invoke) and a way to let your existing Win32 applications call .NET assembly libraries (Inverse P/Invoke, or Managed Exports). At the time it was released, Delphi was the only high-level language to provide this feature, don't know if C# now supports it as well

Some More Info on C++/CL

As a conclusion (I've decided to give my opinion first, this time) let me quote and comment a few relevant elements from the book chapter mentioned earlier, C++/CLI in Action by Nishant Sivakumar:

  • "C++/CLI improves over the now obsolete Managed C++ syntax": Microsoft has made obsolete language extensions introduced a few years ago. Think about the code investsments now lost...
  • "C++/CLI allows the reuse of a developer's native C++ code base, saving the agony of having to rewrite all his existing code...": in Delphi the picture is very different.
  • "In practice, you may find that you would have to change a small percentage of your code to successfully compile and build your applications." Even in C++/CLI compatibility is not perfect, like it is not moving from Delphi to Delphi .NET
  • "Imagine that you have a substantially large MFC application... Take VC++ 2005, recompile the MFC application for the CLR, change the UI layer to use the Windows Forms library". Now, in Delphi you don't have to change the UI layer. This is a huge advantage Delphi has!

Some Comments on the Newsgroup Posts

I've seen in that thread many newsgroup posts I disagree with, but also a few critical voices I agree with. Anyway,

  • John Kaster mentioned that "A mixed mode compiler has been discussed for more than 2 years internally." and that "There is no internal concensus. That's why it's being discussed ;)".
  • Kostya sais "[should have done mixed-mode] Instead of splitting product in .NET/Native so people have to make a choices instead of just hummin' along." I don't buy it: I have medium-sized app with single source I can compile both in Win32 and .NET. You don't have to choose, you can support both!
  • As Markus Humm mentions, Delphi supprots "unsafe code": I already achieved to get some checksum algorithm which uses pointers much running under .NET without any hassle just by declairing it {$UNSAFE ON}." This might not be the perfect solution, but it good enough in many cases.
  • I fully agree with TeamB'er Alisdair, summarized as: "Take another look at what you get from Delphi, and you will see that Delphi2006 already offers something significantly better in many ways".
  • Of relevance, Bjarne Stroustup in person corrected a poster quoting him on this topic, underlining he does not like Microsoft creating a new C++ standard, but this is at least better than having a new language with no standard at all.

That's it. Quite a long post. To summarize, I'm not saying mixed-mode won't be useful for some develoeprs. I claim the current strategy is far better.. You don't get MFC for .NET, you get VCL for .NET. And I really like having it.