2017-04-27 31 views
0

我试图导入一个.NET程序集到德尔福创造“_TLB.pas”的文件,但是我收到一个错误:导入.NET程序集到德尔福失败

Screen shot of error

是什么原因造成这个错误?

.NET程序集是不是使用正确的程序集属性构建的?

XE4可以导入的.NET版本(4.6.1)有限制吗?

下面显示的.NET程序集是使用VS 2012在.NET 4.6.1上创建的。

用Delphi XE4,按照下列步骤:

  • 组件 - >导入组件 - >导入类型库
  • 点击
  • 浏览 '添加' 到.NET程序集。

选择装配体时,发生错误。

构建.NET程序集后,我成功地将它放入GAC(gacutil),将其注册到程序集(regasm)中,然后将其作为组件添加到COM +应用程序中。

我已经尝试创建.tlbregasm并导入,但同样的错误发生。

ObjectCache.cs:

using System; 
using System.EnterpriseServices; 
using System.Runtime.InteropServices; 

namespace TestObjectCache 
{ 
    [Guid("7B1FEFFD-1569-404F-B7EB-6AAB903B8779")] 
    [ComVisible(true)] 
    public interface IObjectCache 
    { 
     Boolean GetTrue(); 
    } 

    [Guid("80C986C4-6B1F-4E3C-9B5E-13943DD1E1FD")] 
    [ComVisible(true)] 
    [ProgId("ProgId.ObjectCache")] 
    [ClassInterface(ClassInterfaceType.AutoDual)] 
    public class ObjectCache:ServicedComponent, IObjectCache 
    { 
     public ObjectCache() 
     { 
     } 
     public Boolean GetTrue() 
     { 
      return true; 
     } 
    } 
} 

的AssemblyInfo.cs:

[assembly: ApplicationActivation(ActivationOption.Server)] 
[assembly: ApplicationName("Object Cache")] 
[assembly: Description("Caches commonly used objects")] 
[assembly: ApplicationAccessControl(false)] 
+0

我不能肯定地说,但对此的“直觉”感觉是.NET命名空间'EnterpriseServices'阻止Delphi能够导入其类型库。如果未使用“EnterpriseServices”,则仍然使用InteropServices,然后可以将类型库导入到Delphi中。可能是由于Windows API无法通过“EnterpriseServices”获得。如果我有时间来验证这一点,我会更新这篇文章。 – ogglethorp

+0

我刚刚使用InteropServices而不是EnterpriseServices来推进。 – ogglethorp

回答

1

通过Visual Studio的Tlbexp.exe工具运行大会产生.tlb文件,然后将该文件导入德尔福。

否则,请尝试使用导入程序的“导入.NET程序集”选项,而不是“导入类型库”选项。

+0

我试着将从Tlbexp.exe生成的.tlb作为从regasm生成的.tlb导入时出现相同的错误。 使用“导入.NET程序集”也失败,但此选项不允许创建_TLB.pas文件。 – ogglethorp