tags:

views:

758

answers:

5

I currently have a codebase of delphi (win32) code. I want to extend new functionality, however, my knowledge is in .NET (C#), and I'd like to keep the existing code base and add new functionality in .NET.

What , if any, are my options (for delphi and .NET inter operating) ?

Thanks!

+5  A: 

There are a few options:

  • It is possible to create and expose a .NET class in an assembly as a COM control (interop) so that it is usable in Delphi.

  • Delphi was .Net for a while (but it wasn't Delphi's brightest hour), so with Delphi 2006 for example you can use Delphi as a .Net language. However just like, if not more so, any other Delphi version change, there are incompatiblities with older source code.

EDIT To do the first method, you'll want to create your assembly with classes/functionality you need in a .NET language and compile it. You should end up with a DLL.

In Delphi, under the Component menu, select Import Component (it should be below Install Packages). You'll get a wizard which should have 3 radio options

  • Import Type library
  • Import ActiveX control
  • Import .NET Assembly

Choose the third and you'll see a list of globally registered assemblies. Since your assembly is just an anonymous DLL, click Add near the bottom and in the open dialog select the DLL.

On the next page you'll be asked for palette information. Here you have a choice - specify your projects folder and leave "Generate Component Wrappers" unchecked to add the assembly to your project only. The other choice is to put it in the lib or other global folder and check the wrapper option, which will add it to the tool palette for all projects.

The last screen will ask if you want to add it to your current project (depends on if you where adding it globally or just to one project).

When all is done you should be able to create instances of your .Net class in Delphi with something like this:

var MyCSharpClassInstance: TMyCSharpClassProvider;
begin
     MyCSharpClassInstance:=CoTMyCSharpClassProvider.Create;
     …
     MyCSharpClassInstance.Free;
End
David
+2  A: 

You can compile your Delphi code for .NET using latest Delphi Prism (ie 2009). It is possible to make a .NET assembly out of Delphi files and them extend that classes using regularly C#.

If your classes are sealed you can also use extension methods.

Augusto Radtke
Careful. Prism is *not* compatible with Delphi code in many ways. You can get an overview here: http://prismwiki.codegear.com/en/Win32_Delphi_vs._Delphi_Prism
Mason Wheeler
A: 

I believe Delphi, as of several versions ago, has .NET compilation.

http://www.codegear.com/products/bds2006

"Developer Studio 2006 includes complete RAD support for C and C# in addition to Delphi Win32 and Delphi for .NET programming languages."

Mystere Man
Doesn't help, because there is no interoperability between dotNET and native languages, even though they used the same IDE.
dummzeuch
There doesn't need to be interoperability, you just compile the language in .NET. Yes, I know, easier said than done, but it's still a solution to .NET.
Mystere Man
A: 

You could have a look here, they produce a compiler for Delphi.Net. This could possibly be a way forward.

Blounty
@Blounty: Oxygene is now Delphi Prism, and is available through CodeGear. I don't think Oxygene is available for separate purchase anymore (although for some reason I can't get to the RemObjects site from here right now to check).
Ken White
+6  A: 

I haven't used it, but check out RemObject Hydra.

Hydra makes it easy mix and match native Delphi and managed .NET code in a single application, allowing developers to choose the best set of technologies for their needs.

Basically you can embed Visual and non-visual .NET code in your Delphi application and work with it just like it is Delphi native. They have a free trial, and there is a contest running right now where you can win a free copy by reviewing the free trial.

Beyond that then you can use .NET via COM in Delphi. The .NET Assembly can be in C#, Prism, VB.NET or any .NET language.

Jim McKeeth
+1 for .NET via COM. Its not that hard to set up, and it works well for non visual functionality (or standalone forms). For the visual embedded plugins you will want to use Hydra.
skamradt