Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi's interoperability with .NET

Tags:

.net

delphi

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!

like image 321
user71947 Avatar asked Feb 27 '09 16:02

user71947


3 Answers

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.

like image 126
Jim McKeeth Avatar answered Nov 10 '22 12:11

Jim McKeeth


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
like image 41
David Avatar answered Nov 10 '22 10:11

David


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.

like image 42
Edwin Jarvis Avatar answered Nov 10 '22 11:11

Edwin Jarvis