Exposing C# COM server Events to Delphi client
-
Hi everyone, I have a C# COM dll which I've add to my delphi application . I can access to its methods and properties successfully .but I cannot access to its events . this is the sample C# code that I found and used: [ComVisible(false)] public delegate void CallArrived(object sender, string callData); /// <summary> /// Interface to expose SimpleAgent events to COM /// </summary> [ComVisible(true)] [GuidAttribute("1FFBFF09-3AF0-4F06-998D-7F4B6CB978DD")] [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface IAgentEvents { ///<summary> /// Handles incoming calls from the predictive manager. ///</summary> ///<param name="sender">The class that initiated this event</param> ///<param name="callData">The data associated with the incoming call.</param> [DispId(1)] void OnCallArrived(object sender, string callData); } /// <summary> /// Represents the agent side of the system. This is usually related to UI interactions. /// </summary> [ComVisible(true)] [GuidAttribute("EF00685F-1C14-4D05-9EFA-538B3137D86C")] [ClassInterface(ClassInterfaceType.None)] [ComSourceInterfaces(typeof(IAgentEvents))] public class SimpleAgent { /// <summary> /// Occurs when a call arrives. /// </summary> public event CallArrived OnCallArrived; public SimpleAgent() {} public string AgentName { get; set; } public string CurrentPhoneNumber { get; set; } public void FireOffCall() { if (OnCallArrived != null) { OnCallArrived(this, "555-123-4567"); } } } and this is the Delphi Sample code which I used : procedure TForm1.Button1Click(Sender: TObject); var intrf : SimpleAgent; begin intrf.AgentName ('Name'); end; I'll appreciate it if anyone could show me the way to access the Event . Best Regards, Shialn
-
Hi everyone, I have a C# COM dll which I've add to my delphi application . I can access to its methods and properties successfully .but I cannot access to its events . this is the sample C# code that I found and used: [ComVisible(false)] public delegate void CallArrived(object sender, string callData); /// <summary> /// Interface to expose SimpleAgent events to COM /// </summary> [ComVisible(true)] [GuidAttribute("1FFBFF09-3AF0-4F06-998D-7F4B6CB978DD")] [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface IAgentEvents { ///<summary> /// Handles incoming calls from the predictive manager. ///</summary> ///<param name="sender">The class that initiated this event</param> ///<param name="callData">The data associated with the incoming call.</param> [DispId(1)] void OnCallArrived(object sender, string callData); } /// <summary> /// Represents the agent side of the system. This is usually related to UI interactions. /// </summary> [ComVisible(true)] [GuidAttribute("EF00685F-1C14-4D05-9EFA-538B3137D86C")] [ClassInterface(ClassInterfaceType.None)] [ComSourceInterfaces(typeof(IAgentEvents))] public class SimpleAgent { /// <summary> /// Occurs when a call arrives. /// </summary> public event CallArrived OnCallArrived; public SimpleAgent() {} public string AgentName { get; set; } public string CurrentPhoneNumber { get; set; } public void FireOffCall() { if (OnCallArrived != null) { OnCallArrived(this, "555-123-4567"); } } } and this is the Delphi Sample code which I used : procedure TForm1.Button1Click(Sender: TObject); var intrf : SimpleAgent; begin intrf.AgentName ('Name'); end; I'll appreciate it if anyone could show me the way to access the Event . Best Regards, Shialn
First you need to create a procedure to handle the event, with the same signature as the delegate e.g. procedure CallArrivedHandler(Sender TObject, Message string) begin //Your event handling code end Then you need to point your CallArrived member at the procedure... CallArrived := CallArivedHandler; And that should do it. (Apologies for syntax errors - from memory, and I haven't Delphi'd for a few years)