我的問題是非常相似,這兩個:將C#COM服務器事件德爾福的客戶端應用
C# - writing a COM server - events not firing on client
然而,是什麼讓他們的工作是不是爲我工作。類型庫文件沒有任何事件定義提示,所以Delphi沒有看到它。正如您所期望的,該類對其他C#應用程序正常工作。
COM服務器工具:
- Visual Studio 2010中
- .NET 4.0
Delphi應用程序:
- 德爾福2010
- 德爾福7
下面的代碼的簡化版本:
/// <summary>
/// Call has arrived delegate.
/// </summary>
[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");
}
}
}
類型庫文件具有的屬性和方法的定義,但沒有事件是可見的。我甚至在Delphi的查看器中打開了類型庫以確保。 Delphi應用程序可以很好地查看和使用任何屬性,方法和函數。它只是沒有看到事件。
我會很感激任何指針或文章閱讀。
謝謝!
該鏈接似乎損壞;文章仍然在線嗎?非常感謝! – 2010-10-08 13:12:34
我的網站死了,備份沒有那個博客文章。我會看看我是否可以在這個週末重新創建這個帖子。 – 2010-10-08 23:12:39