Delphi 7 导入类型库时不生成 COM 类

Delphi 7 not generating COM classes when importing Type Library

在 C# 中,我的解决方案中有一个 class 及其接口,我希望它们对 COM 可见。

我有:

  1. 创建界面和 class 如下:

    [InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("0D1ABB24-144E-4C88-A4A5-DC3ED0E61BEB")]
    [ComVisible(true)]
    public interface IMyInterface
    {
        // methods here
    }
    
    [ClassInterface(ClassInterfaceType.None), Guid("01AA5822-83D1-42C6-A578-C9A84AB836AA")]
    [ComVisible(true)]
    public class MyClass : IMyInterface
    {
        // implementation here
    }
    

    (注意它们都是 COM 可见的)

  2. 生成了一个 GUID 并在程序集信息中通知它:

    [assembly: Guid("MY-GUID-HERE")]
    
  3. 使用此命令行注册它:

    c:\regasm.exe /tlb MyAssembly.Dll
    
  4. 在 Delphi 7.

  5. 中导入了类型库

生成了一个单元,但不包含class和functions/procedures。调用 CoClass.Create 返回 "Class not registered" 错误。

后来我用 class 库创建了一个新的解决方案,执行上面相同的操作,生成的 classes/methods 我可以访问它们。

是否有任何关于我可能错过的提示?

我发现了区别。 我想导出的一个 TLB class 在一个区域中有一些构造函数。当我展开它时,我看到没有无参数的重载构造函数。 添加了一个no-argument构造函数后,在Delphi可见,我可以正常使用