.NET assembly import into Delphi

Good morning

I’m new here and not very familiar with Hydra.

I’m using the evaluating version (v6.5.0.1295) and I would like to import a dll library written in C# (.NET assembly) into a VCL Delphi project.

Currently I’m using Embarcadero Delphi 10.2 build 3.

I searched for some guidelines and I looked into the example folder, but I cannot find something really helpful.

I tried the ‘Module Explore’ example but I cannot load my dll with this application.

In addition, I don’t know how to use the function ‘Import from .NET Assemblies’ from Delphi’s Tools, because running it on my dll, the unit .pas generated an empty result even if I didn’t get any error.

Any suggestion would be appreciated.

Thanks in advance.

Marco

Hi,

Pls review the Delphi WPF sample.

it has

    [Guid("8032a51c-5961-41f5-9582-c77d98ea4d93")]
    public interface IVisualizerControl : IHYCrossPlatformInterface
    {
        bool BarsVisible { get; set; }
        void Randomize();
        void Sinus(Double aRange);
    }

that can be imported with Import from .NET Assemblies into Delphi unit.

also the Passing Interfaces between Host and Plugins article can be useful if you want to communicate between Delphi and .NET.

Thanks @EvgenyK for the quick reply.

I tried the Delphi WPF sample and it works fine.

Since the dll library that I have to import it is not written with the basic plugin interface (I tried to import it, but the .pas file is empty) and I cannot modify the dll project:

  • is there a chance to create a wrapper to add the plugin interface?
  • if yes, is it possible to do it automatically or I have to do it by myself?

Thanks in advance again.

Hi,

You should create a wrapper for .NET assembly.
It can’t be done automatically so you have to create it manually.
Note: usually you don’t need all members so you can put only needed methods/properties to wrapper.

Since I’m not familiar with C# syntax and, in particular, with C# interfaces… can you suggest me an example with a simple plugin as wrapper?

Hi,

Have you read the Delphi WPF Sample article?

it describes these parts:

  • Interface
  • Wrapper
  • Plugin

Yeah, I understood the concept but I’m having some troubles implementing the C# wrapper, since I’m not familiar with the language.

Thanks anyway.

Hi,

you can write wrapper with Pascal-like syntax.
Check RemObjects Oxygene (Object Pascal)