Delphi和Lazarus(FPC)接口的实现有什么区别? [英] What are the differences between implementation of Interfaces in Delphi and Lazarus (FPC)?

查看:1030
本文介绍了Delphi和Lazarus(FPC)接口的实现有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个充满了现在在拉撒路和德尔福工作的定制组件的项目。



我在考虑代码接口,但我不是很多熟悉他们我想知道的是:Delphi和Lazarus接口的实现细节是什么?有什么我应该特别注意的?我必须编写真正不同的东西吗?



背景说明:
我认为这些组件可以从界面中受益,至少我会从中学到更多。例如,其中一个组件使用串行端口与许多不同的硬件进行通信。但用户只能使用我们的组件来创建应用程序。所以我们有一个组件和一个类,每个这个硬件从后裔的基类。在运行时,我们在组件中创建特定的类。



不知道最后一个解释是否需要,但是如果有任何需要,我可以写更多。 p>

解决方案

在Free Pascal中,界面类型取决于模式。基本上有模式 COM或CORBA 。 COM是默认的,与Delphi大致兼容。 CORBA是一个比较简单的例子,没有引用计数。 (并且因此也不产生对计费功能的调用)。因此,基本上一个FPC Corba界面就像IUnknown接口的假设祖先一样。



除此之外,接口发布时有时会有一些差异。 Delphi倾向于在程序或块(在较大的程序中)结束时减少引用计数,而FPC有时被称为通常在最后使用语句之后立即释放它们。两者都是合法实施选择btw,基于哪个范围用于临时变量。 (仅在功能级别上,或者在更深的嵌套块中)



然而,这有时会在代码中显示隐藏(坏)假设,特别是在使用接口引用和对象引用时一个程序可能在德尔福幸存,但不是在FPC。这是一个典型的情况,表明长时间的工作代码不一定正确。在更改实现时,可能只会注意到隐藏的假设。



(稍后添加:)注意,您可以在* nix上使用COM样式。它主要是将引用计数例程的调用插入到两个接口类型之间。不是什么系统(COM,Corba或简单的RTL引用计数)这些调用被路由到。



请注意,我认为两个接口类型的COM和Corba名称是不好的选择。 Corba接口实际上是被计数的,但是传统上这个引用计数是手工处理的,因为Java不能以自动的方式支持外部处理的接口。


We have a project full of custom components that today is working in Lazarus and Delphi.

I'm thinking in code interfaces on it, but I am not much familiar with them. What I would like to know is: What are the implementation nuances from Delphi and Lazarus interfaces? There is something that I should be specially aware? Will I have to code really different things?

Background explanation: I think the components could benefit from interfaces, or at least, I will learn more from them. For example, one of the components make communication to many different hardwares using serial port. But user should use only our component to create the application. So we have the component and one class to each of this hardware that descendant from a base class. At run-time we create the specific class inside the component.

Not sure this last explanation was needed, but I can write more if any of you need it.

解决方案

In Free Pascal, the interface type depends on mode. Basically there is mode COM or CORBA . COM is default and roughly compatible with Delphi. CORBA is a more simpler case without the reference counting. (and thus also not generating calls to refcounting functions). So basically a FPC Corba interface is like the hypothetical ancestor of the IUnknown interface.

Besides this, there are sometimes some differences wrt when interfaces are released. Delphi tends to save decreasing the refcount at for the end of the procedure or block (in larger procedures), while FPC sometimes is known to release them sooner, typically immediately after the statement of last use. Both are legal implementation choices btw, base on which scope is used for temporary variables. (only on the function level, or also in deeper nested blocks)

However this sometimes reveals hidden (bad) assumptions in code, specially when using interface references and object references within one procedure that might "survive" in Delphi, but not in FPC. It is a typical case that shows that long-time working code is not necessarily correct. One might only notice hidden assumptions when changing implementation

(added later:) note that you can use COM style on *nix. It mainly is the insertion of calls to reference counting routines that set the two interface types apart. Not what system (COM, Corba or simply in RTL reference counting) those calls are routed to.

Note that I think the COM vs Corba names for both interface types were badly chosen. Corba interfaces are refcounted actually, but traditionally this refcount is manually handled, because Java does not support externally handled interfaces in an automated manner.

这篇关于Delphi和Lazarus(FPC)接口的实现有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆