Inherited interfaces from .net dll


(Phillip Watson) #1

I have a .net dll (Simple.Interfaces) that contains interface definitions for various entities.
An example is

public interface ICustomer, IPerson, IEntity

ICustomer declares customer specific properties and IPerson declares general person properties like name etc
This .net dll (Simple.Interfaces) has no reference to any Hydra interfaces and has no other dependencies, the interfaces do not have Guid attributes and the .dll is not com visible.

I want to create a .net non visual plugin that I can then import in to Delphi. The interfaces declared in the plugin are as follows. My idea is to create a “wrapper” interface that implements the IHYCrossPlatformInterface as required but also the ICustomer interface.

[Guid(“C5892A97-A996-44D5-A06A-D93C9FF9E509”)]
public interface ICustomerHydra : IHYCrossPlatformInterface, ICustomer

The plugin project has a reference to the first .net dll (Simple.Interfaces) and hence can use ICustomer from that dll.
When I import the plugin in to Delphi it only imports an empty ICustomerHydra interface with no properties inherited from ICustomer. It looks like it is trying because the auto generated import module is referencing another import module in it’s uses that is named like the Simple_Interfaces_Import but that unit does not exist. It has not actually been generated. As shown

interface
uses
uHYCrossPlatformInterfaces, Simple_Interfaces_Import;
type
ICustomerHydra = interface;

// Original Name: Module.Interfaces.ICustomerHydra
ICustomerHydra = interface(IHYCrossPlatformInterface)
[’{c5892a97-a996-44d5-a06a-d93c9ff9e509}’]
end;

Is there a way of having the import use the properties inherited from ICustomer, IPerson or will I have to manually maintain the ICustomerHydra and declare the accumulated properties from ICustomer and IPerson explicitly?
I have tried decorating the ICustomer interface in Simple.Interfaces with a Guid attribute and making it com visible but that didn’t help any. I got exactly the same generated import unit.
Is the importer not capable of generating code that uses the multiple interfaces? Why is it failing to generate Simple_Interfaces_Import if that is the problem?
Is there something I need to do to make it work as I want?
Using Hydra 5, Visual Studio 2017, Delphi XE6.
Please advise.

Regards


(antonk) #3

Hello

In case of Delphi <-> .NET communications Hydra actually uses COM.

In COM interfaces can inherit from one another. However the .NET implementation that exposes the .NET interface to COM does not support inheritance. Therefore you must replicate any interface members in a base interface to the derived interface.

More details at https://social.msdn.microsoft.com/Forums/vstudio/en-US/7313191a-10db-4a16-9cdd-de9fb80b378a/com-interop-base-class-properties-not-exposed-to-com?forum=csharpgeneral

Regards


(Phillip Watson) #4

Okay, thanks for your help and clarification will implement the properties explicitly on the hydra interface.