I have been tinkering with this for a few days, without any results. Here's the story, my current employer is using VS 2010 and C#. We have a client that uses Delphi 7. I'm the only one on my employer's team that knows anything about Delphi. So I'm tasked with creating a COM server out of our code. The type library exports the properties, functions, and procedures just fine. It's the events that are giving me grief.
So here's a simplified version of the C# code:
[Guid("3D205377-9130-442B-AB12-8056DD7A3192"),
ClassInterface(ClassInterfaceType.AutoDual)]
public class SILAgent : MarshalByRefObject
{
public delegate void CallArrived(object sender, CallRecievedEventArgs callData);
public event CallArrived OnCallArrived;
public string IpAddress { get; set; }
public int Port { get; set; }
}
When I import the type library into Delphi it looks like this:
// *********************************************************************//
// Interface: _CallRecievedEventArgs
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {373EA64B-BD3D-37EF-906E-CDB169F6B6E7}
// *********************************************************************//
_CallRecievedEventArgs = interface(IDispatch)
['{373EA64B-BD3D-37EF-906E-CDB169F6B6E7}']
function Get_ToString: WideString; safecall;
function Equals(obj: OleVariant): WordBool; safecall;
function GetHashCode: Integer; safecall;
function GetType: _Type; safecall;
function Get_PhoneNumber: WideString; safecall;
procedure Set_PhoneNumber(const pRetVal: WideString); safecall;
function Get_CallProgress: WideString; safecall;
procedure Set_CallProgress(const pRetVal: WideString); safecall;
function Get_UniqueId: WideString; safecall;
procedure Set_UniqueId(const pRetVal: WideString); safecall;
function Get_ProjectId: Int64; safecall;
procedure Set_ProjectId(pRetVal: Int64); safecall;
function Get_CallStatus: CallProgressStates; safecall;
procedure Set_CallStatus(pRetVal: CallProgressStates); safecall;
function Get_Disposition: WideString; safecall;
procedure Set_Disposition(const pRetVal: WideString); safecall;
function Get_InfoXML: WideString; safecall;
procedure Set_InfoXML(const pRetVal: WideString); safecall;
procedure ParseMessage(const message: WideString); safecall;
property ToString: WideString read Get_ToString;
property PhoneNumber: WideString read Get_PhoneNumber write Set_PhoneNumber;
property CallProgress: WideString read Get_CallProgress write Set_CallProgress;
property UniqueId: WideString read Get_UniqueId write Set_UniqueId;
property ProjectId: Int64 read Get_ProjectId write Set_ProjectId;
property CallStatus: CallProgressStates read Get_CallStatus write Set_CallStatus;
property Disposition: WideString read Get_Disposition write Set_Disposition;
property InfoXML: WideString read Get_InfoXML write Set_InfoXML;
end;
// *********************************************************************//
// Interface: _CallArrived
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {3901A611-72B3-3EB9-BCAA-B5FDCB29F782}
// *********************************************************************//
_CallArrived = interface(IDispatch)
['{3901A611-72B3-3EB9-BCAA-B5FDCB29F782}']
end;
// *********************************************************************//
// DispIntf: _CallArrivedDisp
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {3901A611-72B3-3EB9-BCAA-B5FDCB29F782}
// *********************************************************************//
_CallArrivedDisp = dispinterface
['{3901A611-72B3-3EB9-BCAA-B5FDCB29F782}']
end;
// *********************************************************************//
// Interface: _SILAgent
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {3131BA8A-BFA2-3D7F-9813-904EA285B121}
// *********************************************************************//
_SILAgent = interface(IDispatch)
['{3131BA8A-BFA2-3D7F-9813-904EA285B121}']
procedure add_OnCallArrived(const value: _CallArrived); safecall;
procedure remove_OnCallArrived(const value: _CallArrived); safecall;
property IpAddress: WideString read Get_IpAddress write Set_IpAddress;
property Port: Integer read Get_Port write Set_Port;
end;
I did notice that the tlb import file has both an add and remove procedures. So in Delphi I would do something like this:
procedure TForm1.FormCreate(Sender: TObject);
begin
TestAgent := CoSILAgent.Create;
TestAgent.Init;
TestAgent.add_OnCallArrived();
end;
I just can't seem to figure out what should the parameter to add_OnCallArrived() should be. Should I create a procedure with the same signature as the C# delegate and assign it to add_OnCallArrived() as a parameter? Can somebody point me in the right direction?
Thanks!