如何使用 VCL 类的接口 - 第 2 部分
继续我之前关于使用 VCL 接口的调查。
我想要一个代码示例来演示两者在何处以及如何协同工作。 或者两者的经典好处/用途是什么:
ISomething = interface
['{EFE0308B-A85D-4DF3-889C-40FBC8FE84D0}']
...
end;
TSomeThing = class(TSomeVCLObject, ISomething)
...
end;
continue with my previous investigation regarding the use of Interface with VCL.
How to implement identical methods with 2 and more Classes?
How to use Interface with VCL Classes?
I would like to have a code example to demonstrate where and how the two work together.
Or what is the classic benefit/usage of the two:
ISomething = interface
['{EFE0308B-A85D-4DF3-889C-40FBC8FE84D0}']
...
end;
TSomeThing = class(TSomeVCLObject, ISomething)
...
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

想象一下,您有
TSomeThing
和TSomeThingElse
类,但它们没有共同的祖先类。按原样,您将无法将它们传递给同一函数,或对它们调用通用方法。通过向两个类添加共享接口,您可以同时执行这两项操作,例如:Imagine you have
TSomeThing
andTSomeThingElse
classes, but they do not have a common ancestor class. As-is, you would not be able to pass them to the same function, or call a common method on them. By adding a shared interface to both classes, you can do both, eg: