3
votes

When I import tlb file that is specific to a .net dll, into Delphi using type library importer, the methods which accept parameters of type .net specific, are replaced by IUnknown. When I want to invoke such method from my Delphi client application, I would like to pass a parameter value of type SQLTransaction. How do I achieve this? Do I need to change all the .net dll method parameters to user defined types that inherit from .net specific types?

I also have mscorlib_TLB.pas imported when I improted .net tlb.

.net method

public class MyConnection : IDisposable
{    
    public int BulkInsert(SqlTransaction tran);
    {...}
}

Method in Delphi imported tlb:

_MyConnection = interface(IDispatch)
    ['{9FB088F8-1033-3A99-B9C6-C7D7D2D40140}']    
    function BulkInsert(const SQLTransaction: IUnknown): int; safecall;
end;
  CoMyConnection = class
    class function Create: _MyConnection;
    class function CreateRemote(const MachineName: string): _MyConnection;
  end;

how do I call the BulkInsert method from my Delphi client application?

2

2 Answers

3
votes

That is entirely to be expected. The SqlTransaction type is a .net type, unknown to your COM interface. How can you expect some other party, a Delphi program in this case, to be able to obtain an instance of the .net SqlTransaction type.

Your COM interface needs to restrict itself to use only COM types. You will need to replace SqlTransaction with a COM interface. One way to approach the problem is to declare a COM interface, that exposes the necessary functionality of SqlTransaction. Then in your C# Code create a type that implements this interface by delegating the implementation to an instance of SqlTransaction. Then expose a method that allows instantiation of your wrapper interface. On the Delphi side the consumer will instantiate your wrapper interface and pass that to BulkInsert. Naturally you'll change BulkInsert to accept as its parameter the wrapper interface rather than SqlTransaction.

1
votes

maybe you should first obtain the Interop proxy objects, usually importing a type library in a visual studio project it is done automatically by the ide, I think that Delphy ought to implement the same feature, but I don't sure..