Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
Hi,

I would like to know if it is possible to have a C# windows form integrate into delphi, so that the form sits inside a delphi frame.

Thanks


What I have tried:

I have created a windows form project, converted it to dll by changing the output type, called from a console application, and it works.
Posted
Updated 5-Jun-16 18:42pm
Comments
Sergey Alexandrovich Kryukov 5-Jun-16 19:54pm    
Delphi.NET or natively targeted Delphi project?
—SA

1 solution

If you are talking about Delphi for .NET, such problem simply does not exist. You can create different assemblies in different .NET languages and freely combine them.

This is really difficult to do if you mean Delphi projects targeted to native code. The other way around, using a DLL created in Delphi, would not be a problem. However, the usual way of using .NET UI in native projects would be creation of an ActiveX control using .NET, but I don't want to discuss it, as it uses obsolete technology. You can always read about it in MSDN documentation.

Another alternative is exporting .NET methods you create in your .NET assembly to native. This is not a trivial approach (many would even say it is impossible, but in fact it is not routinely supported by, say, Visual Studio, but it allowed by the CLI standad). Please see these CodeProject answers:
API's in .Net: Managed or UnManaged Code[^],
Call Managed DLL written in C# from Unmanged Code VC++[^],
How can I use a dll created in Visual Basic 2008 in Visual Basic 6.0[^],
loading C# DLL in MFC[^].

Another approach would be using C++/CLI instead of C#. More exactly, you main assemblies can be in C#, but you can also created an intermediate-layer project in C++/CLI with the sole purpose of exposing managed code by wrapping it in some unmanaged functions which you can then use in your Delphi project by linking a DLL in a usual way and using those exported functions. Please see my past answers:
How do I pass a string from a c# app to class ctor in a c++ cli dll?[^],
How the Keyboard Hook works and how it is being implemented[^].

Please don't be confused: even though I discuss using C++/CLI for invocation of unmanaged code, it can be used for the other way around.

And now, the last but not the least: think seriously: do you really need all the trouble?
Delphi is very powerful, you can do a lot with Delphi along, without the help of .NET. If you have trouble with some functionality, perhaps you may want to ask some questions. Better yet, you can use such a great alternative to .NET as open-source Free Pascal, with Lazarus. Lazarus is not only the IDE, it also provides the lcl UI library, the analog of Delphi VCL. The major difference is: it is truly multi-platfrorm. In practice, it covers a lot more platforms than .NET and many other technologies. Amazingly, lcl is multi-platform, too. You really can have the same code for very many OS, even for really tiny embedded or smartphone devices.
Please see:
Lazarus wiki[^],
Lazarus Homepage[^].

When you download and install Lazarus, Free Pascal and all the libraries are included. Probably this is the strongest alternative to .NET available, but it's native; you will have to compile your projects on each platform separately. Some support of cross-platform compilation is also provided, but at this moment it's more difficult.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900