4

我有一些在 .NET 中实现的业务逻辑和一些在 Delphi 中实现的业务逻辑。现在我打算升级到 Delphi XE2。

我们是否有任何规定可以使用 Delphi XE2 的 .net 程序集?

更新:我听说Hydra 框架使我们能够集成托管和非托管代码。任何人都可以用一个小的演示/代码片段来解释更多吗?

更新:我在这个Hydra Framework的试用版上尝试了一些东西。但它还需要修改您的 .NET 程序集以创建接口,以便我们可以将其映射到 Delphi 代码。

有什么方法可以在不修改的情况下使用 .NET 程序集?

4

4 回答 4

4

看看AToZed CrossTalk,它可以直接使用 .NET 程序集,而无需使用 COM 互操作。

于 2011-11-03T17:29:49.380 回答
1

Nilesh, 我只能从Delphi 6的 presepctive 来回答这个问题,所以请记住 Delphi XE2 可能有更新的 .NET 互操作选项。

因此,要从(您的)Delphi 6 应用程序使用(您的).NET 程序集功能,最简单的方法是将 .NET 程序集修改为 COM 可见,并在 Delphi 中以正常方式简单地使用所述 COM 接口。

来自 .NET 项目;将您需要的功能提取到一个(或多个接口)中,将 GUI 属性应用于这些接口。在项目选项中将项目标记为“COM Visible”并重建。您需要使用 COM 注册程序集(如果有记忆,请从命令行运行 regsvr!)

来自德尔福;执行类型库的导入以从程序集 DLL 获取 TLB,然后只需 CoCreate() 与适当的 GUID 并像任何其他 COM 库一样使用。

于 2011-11-03T12:36:22.757 回答
1

About XE2, the only possibly breaking new feature shall be 64 bit.

But from the COM point of view, it may matter for a COM object to be implemented or called in either a 32 bit or 64 bit code.

COM object types are registered via registry keys. This is what the regasm.exe utility does (writes to the registry). 32-bit bit registry nodes and distinctly different than 64-bit registry nodes.

For instance, if your COM object is compiled as 32 bit, it shall be registered in the 32 bit registry or the 64 bit registry (via reagasm calls)

But if you stick with 32 bit Delphi application, you won't have any additional issue, if you specify the COM wrapper to be exported as 32 bit. In short, XE2 behaves exactly the same as any previous version of Delphi, when creating 32 bit processes.

See http://www.gfi.com/blog/32bit-object-64bit-environment for additional information.

Another solution could be to run the COM object out of the process: in this case, the bit-ness won't matter, and you should not have any issue about 32 or 64 bit.

Be aware that there was a very annoying bug in XE2: in short, COM access was broken in some cases. Sounds like latest "Update pack 2" solved the issue.

Of course, if you use the cross-platform features of Delphi XE2, your COM object won't be available in Mac OS X. ;)

于 2011-11-03T13:06:26.637 回答
0

您可以执行所谓的非托管导出

Delphi Prism 支持它的语言,C#/VB.NET 不支持。但是有一个项目模板可以使用,请参见作者站点

非托管导出是一种允许本机代码在没有 COM 互操作的情况下调用托管代码的技术。Giesecke 先生有一篇关于这个主题的文章

于 2011-11-04T16:59:58.190 回答