1

I found that there is no way to export a class in Delphi dll. Now I want to use a class exported in a dll file written by C# (i.e. TLSharp class) Is there any way to use this class objects and methods in Delphi?

P.S: I meant using classes exported in a C# dll file in a Delphi program, not using a Delphi dll in a C# program explained at: Delphi's interoperability with .NET

Community
  • 1
  • 1
Alireza Zojaji
  • 802
  • 2
  • 13
  • 33
  • Take a look here: http://stackoverflow.com/questions/595601/delphis-interoperability-with-net. So you can, for instance, use RemObjects Hydra or COM. I would first try the latter. That allows you to use classes (heck, in C#, everything is in a class anyway) like any other COM class. Just see if you can import the assembly (that is how .NET DLLs are called) in the Delphi IDE. – Rudy Velthuis Mar 26 '17 at 11:06
  • Possible duplicate of [Delphi's interoperability with .NET](http://stackoverflow.com/questions/595601/delphis-interoperability-with-net) – Rudy Velthuis Mar 26 '17 at 11:16
  • @rudy that questions asks in the opposite direction – David Heffernan Mar 26 '17 at 11:20
  • @Amir Simplest is to expose the functionality as a COM object – David Heffernan Mar 26 '17 at 11:20
  • @David: does it? "Now I want to use a class exported in a dll file written by C#". The answer says "Basically you can embed Visual and non-visual .NET code in your Delphi application and work with it just like it is Delphi native.". Does he want to consume C# classes in Delphi, or consume Delphi classes in C#? I think it is the former. – Rudy Velthuis Mar 26 '17 at 12:52
  • @rudy You said the question was a duplicate, the answer is not relevant – David Heffernan Mar 26 '17 at 13:21
  • @rudy My purpose is exactly in the opposite way that you considered. I have a dll in C# that exports some classes and want to use these classes in Delphi. – Alireza Zojaji Mar 26 '17 at 14:28
  • @David: Jim's accepted (!) answer answers the other question, which is basically the same as this one, as far as I can tell. That question is also about consuming the classes from a C# assembly in Delphi. This one asks the same, as Amir confirms. – Rudy Velthuis Mar 26 '17 at 16:44
  • @Amir, that is exactly what I considered. As I already said, look if these classes are exported as COM classes from the C# assembly, so you can use them (after importing them -- i.e. let the IDE create a wrapper unit that can access them) in Delphi. If not, use something like Hydra. – Rudy Velthuis Mar 26 '17 at 16:48
  • @RUDY no, amir said the exact opposite. I don't think you understand this site at all. – David Heffernan Mar 26 '17 at 16:48
  • @David: Did you see what Amir wrote to me? He wants to consume C# classes from a C# assembly in his Delphi application. That is what the other question asks too, and what Jim McKeeth answered. The answer was accepted, so it must have been right. I do understand what this site is about. Why do you keep saying that I don't? – Rudy Velthuis Mar 26 '17 at 16:50
  • Try this answer: http://stackoverflow.com/a/6175291/1291717 – Sergey Slepov Mar 26 '17 at 16:52
  • @Sergey: if the user can modify the C# project, that is indeed a viable solution and probably a very easy to use one. – Rudy Velthuis Mar 26 '17 at 16:58
  • @Rudy Read the question, and Amir's comments, and try to imagine a world where it is conceivable that you might be wrong – David Heffernan Mar 26 '17 at 16:59
  • Amir explictly says: "I have a dll in C# that exports some classes and want to use these classes in Delphi." Well, that is exactly what I commented about. What was wrong with that? Also see the title of this question. – Rudy Velthuis Mar 26 '17 at 17:15
  • This question wants to consume C# code in a Delphi host. The question you linked to asks for the reverse. – David Heffernan Mar 26 '17 at 17:20
  • @David: indeed, and that is what I have been saying all the time, and what the other question and accepted answer discuss too. As far as I can tell, the other question does not ask for the reverse. – Rudy Velthuis Mar 26 '17 at 18:25

1 Answers1

-2

I haven't detail information but I can give you a start position. Dll communication managed my operation system. So there is some limits. Data types are limited with primitive data types (long, int, pointer, char, etc). So you cannot share class method between delphi and c# (as pointer yes). You need to develop your communication without using class method. You can create object from class in your dll. Then access it is properties and methods with primitive method. I try to implement embedded mysql library to C# which is developed in C++. May be this open source project give you start point.

mkysoft
  • 5,392
  • 1
  • 21
  • 30