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?
Thanks to Alexander B for sending me down the right direction - there were a few more details I have to add otherwise I would select his input as the correct answer.
So, as I stated in my comments, I imported the tld file in the delphi GUI and used the CoClassName.Create to get access to the objects. Though this gave me errors at run time as the application couldn't find the VB.NET dll, I got the error message 'The system cannot find the file specified' even though I had imported the dll using regasm. I then found the following post
Which states that the flag /codebase must be added to the regasm command. Once I imported the dll using regasm with this flag everything worked perfectly. Hope this helps someone else.