<small id='zT1vr'></small><noframes id='zT1vr'>

      <i id='zT1vr'><tr id='zT1vr'><dt id='zT1vr'><q id='zT1vr'><span id='zT1vr'><b id='zT1vr'><form id='zT1vr'><ins id='zT1vr'></ins><ul id='zT1vr'></ul><sub id='zT1vr'></sub></form><legend id='zT1vr'></legend><bdo id='zT1vr'><pre id='zT1vr'><center id='zT1vr'></center></pre></bdo></b><th id='zT1vr'></th></span></q></dt></tr></i><div id='zT1vr'><tfoot id='zT1vr'></tfoot><dl id='zT1vr'><fieldset id='zT1vr'></fieldset></dl></div>
      1. <tfoot id='zT1vr'></tfoot>

          <bdo id='zT1vr'></bdo><ul id='zT1vr'></ul>
        <legend id='zT1vr'><style id='zT1vr'><dir id='zT1vr'><q id='zT1vr'></q></dir></style></legend>

      2. 向 Delphi 客户端应用程序公开 C# COM 服务器事件

        Exposing C# COM server events to Delphi client applications(向 Delphi 客户端应用程序公开 C# COM 服务器事件)

            <tbody id='V2Og3'></tbody>
          • <bdo id='V2Og3'></bdo><ul id='V2Og3'></ul>

                <legend id='V2Og3'><style id='V2Og3'><dir id='V2Og3'><q id='V2Og3'></q></dir></style></legend>

              • <small id='V2Og3'></small><noframes id='V2Og3'>

                <tfoot id='V2Og3'></tfoot>
                  <i id='V2Og3'><tr id='V2Og3'><dt id='V2Og3'><q id='V2Og3'><span id='V2Og3'><b id='V2Og3'><form id='V2Og3'><ins id='V2Og3'></ins><ul id='V2Og3'></ul><sub id='V2Og3'></sub></form><legend id='V2Og3'></legend><bdo id='V2Og3'><pre id='V2Og3'><center id='V2Og3'></center></pre></bdo></b><th id='V2Og3'></th></span></q></dt></tr></i><div id='V2Og3'><tfoot id='V2Og3'></tfoot><dl id='V2Og3'><fieldset id='V2Og3'></fieldset></dl></div>

                • 本文介绍了向 Delphi 客户端应用程序公开 C# COM 服务器事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的问题和这两个很相似:

                  My question is very similar to these two:

                  C# 组件事件?

                  C# - 编写 COM 服务器 - 事件不在客户端触发

                  但是,对他们有效的方法对我无效.类型库文件没有任何事件定义的提示,所以 Delphi 看不到它.如您所料,该类适用于其他 C# 应用程序.

                  However, what worked for them is not working for me. The type library file, does not have any hints of events definitions, so Delphi doesn't see it. The class works fine for other C# applications, as you would expect.

                  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 应用程序可以很好地查看和使用任何属性、方法和函数.它只是看不到事件.

                  The type library file has the definitions for the properties and methods, but no events are visible. I even opened the type library in Delphi's viewer to make sure. The Delphi app can see and use any property, methods, and functions just fine. It just doesn't see the events.

                  如果有任何建议或文章可供阅读,我将不胜感激.

                  I would appreciate any pointers or articles to read.

                  谢谢!

                  推荐答案

                  经过反复试验,我终于解决了这个问题.我需要对 C# 代码进行两处更改.

                  I finally got this resolved after much trial and error. There were 2 things that I needed to change on the C# code.

                  1) [ClassInterface(ClassInterfaceType.None)] 需要更改为 [ClassInterface(ClassInterfaceType.AutoDual)]

                  1) [ClassInterface(ClassInterfaceType.None)] needed to be changed to [ClassInterface(ClassInterfaceType.AutoDual)]

                  2) 作为事件源的类需要从 MarshalByRefObject 继承.如果在源类中完成了任何线程,这会有所帮助.

                  2) The class that is the source of the events needs to inherit from MarshalByRefObject. This helps if there is any threading done in the source class.

                  我只需要在 Delphi 方面做一件事.我需要确保选中生成组件包装器"复选框.这就是在 Delphi 方面实际构建事件脚手架的原因.

                  I only needed one thing on the Delphi side. I needed to make sure to have the "Generate Component Wrapper" checkbox checked. This is what will actually build the event scaffolding on Delphi's side.

                  这就是你在 Delphi 7 中的做法:

                  This is how you do it in Delphi 7:

                  1. 从菜单项目中选择 -> 导入类型库
                  2. 确保选中生成组件包装器"
                  3. 从列表中选择 COM 类
                  4. 点击添加单元"按钮

                  新单元将具有您的 COM 事件的定义.

                  The new unit will have the definitions of your COM events.

                  关于如何做到这一点的分步博客文章

                  这篇关于向 Delphi 客户端应用程序公开 C# COM 服务器事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)
                • <small id='fdUds'></small><noframes id='fdUds'>

                      • <tfoot id='fdUds'></tfoot>
                        <legend id='fdUds'><style id='fdUds'><dir id='fdUds'><q id='fdUds'></q></dir></style></legend>

                            <tbody id='fdUds'></tbody>
                          <i id='fdUds'><tr id='fdUds'><dt id='fdUds'><q id='fdUds'><span id='fdUds'><b id='fdUds'><form id='fdUds'><ins id='fdUds'></ins><ul id='fdUds'></ul><sub id='fdUds'></sub></form><legend id='fdUds'></legend><bdo id='fdUds'><pre id='fdUds'><center id='fdUds'></center></pre></bdo></b><th id='fdUds'></th></span></q></dt></tr></i><div id='fdUds'><tfoot id='fdUds'></tfoot><dl id='fdUds'><fieldset id='fdUds'></fieldset></dl></div>

                            <bdo id='fdUds'></bdo><ul id='fdUds'></ul>