【问题标题】:IEnumerable.GetEnumerator() returns IEnumVariant in Delphi 6IEnumerable.GetEnumerator() 在 Delphi 6 中返回 IEnumVariant
【发布时间】:2010-10-15 12:15:44
【问题描述】:

我通过 COM 在 Delphi 6 中使用 .Net2.0 程序集。 接口之一中的方法之一返回 IEnumerable。 只要我导入位于

中的 mscorlib.tlb

“C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727”

,我可以在 Delphi 6 中访问 IEnumerable 和 IEnumerator 接口。这是在 mscorlib_TLB.pas 中定义 IEnumerable 的部分:

// *********************************************************************//
// Interface: IEnumerable
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {496B0ABE-CDEE-11D3-88E8-00902754C43A}
// *********************************************************************//
  IEnumerable = interface(IDispatch)
    ['{496B0ABE-CDEE-11D3-88E8-00902754C43A}']
    function GetEnumerator: IEnumVARIANT; safecall;
  end;

GetEnumerator 方法的返回值不是 IEnumerator,当我尝试将其强制转换为 IEnumerator 时会抛出“不支持接口”异常。

以前有没有人遇到过这个或类似的问题?怎么解决?

【问题讨论】:

    标签: delphi com .net-2.0 ienumerable


    【解决方案1】:

    这是通过 COM 互操作与 .NET 对象交互时的标准行为,如下所示:

    http://msdn.microsoft.com/en-us/library/111chfb8(VS.71).aspx

    【讨论】:

      【解决方案2】:

      指向 MSDN 对 IEnumVARIANT 的解释的链接也可能很有价值:http://msdn.microsoft.com/en-us/library/ms221053.aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-22
        • 2015-04-22
        • 2020-08-14
        相关资源
        最近更新 更多