I have a COM class created in VB.NET. I am trying to use it in Delphi 5.0.
I have seen some examples/questions on the topic, namely:
http://www.drbob42.com/delphi/headconv.htm
http://edn.embarcadero.com/article/32754
and others, but these all deal with basic functions and not custom objects.
Firstly, I have registered my VB.NET COM DLL using regasm.
My VB.NET COM object is defined as follows:
<ComClass(Bridge.ClassId, Bridge.InterfaceId, Bridge.EventsId)> _
Public Class Bridge
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
Public Function Quote(ByRef input As InObject) As ReturnObject
BLABLA
End Function
End Class
With an Input class:
<ComClass(InObject.ClassId, InObject.InterfaceId, InObject.EventsId)> _
Public Class InObject
End Class
And a Result class:
<ComClass(ReturnObject.ClassId, ReturnObject.InterfaceId, ReturnObject.EventsId)> _
Public Class ReturnObject
End Class
Please pay no attention to the class names and lack of code in them. I just want to highlight how I am defining them as COM classes.
I can't find any examples of Delphi code calling a method in a COM class, or one that uses custom objects as inputs and returns. But, from the examples I showed above, I thought the line in Delphi to declare the function for use would be like this:
function Bridge.Quote(i: InObject): ReturnObject; external 'Bridge.dll';
This fails to compile. I get an error:
function needs result type
Is there anything obvious that I am doing wrong?
Variantinstead ofReturnObjectin your Delphi function declaration.externalstatement to import a COM object. You need to define the object's COM interfaces in Pascal code and then useCoCreateInstance()or equivalent function to instantiate the COM object at runtime, and then use the interfaces to access it. You can have the Delphi IDE import the .NET assembly so it can extract the relevant COM declarations and generate suitable Pascal code for you.