Delphi 3 中接口支持的等效项是什么?

发布于 2024-10-05 23:48:02 字数 191 浏览 1 评论 0原文

我支持用 Delphi 3 编写的应用程序,并且我想对源代码进行一些改进,同时等待将其升级到较新版本的 Delphi 的机会。我想使用的东西之一是接口。我知道 Delphi 3 已经有了接口的概念,但我很难找到如何做相当于

if Supports(ObjectInstance, IMyInterface) then

I support an application written in Delphi 3 and I would like to put in some improvements to the source code while waiting for the opportunity to upgrade it to a newer version of Delphi. One of the things I would like to use is Interfaces. I know Delphi 3 already has the concept of Interfaces but I am having trouble finding out how to do the equivalent of

if Supports(ObjectInstance, IMyInterface) then

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末蓝 2024-10-12 23:48:02

编写您自己的“支持”功能的实现。在Delphi 2009中您可以使用

function MySupports(const Instance: TObject; const IID: TGUID): Boolean;
var
  Temp: IInterface;
  LUnknown: IUnknown;
begin
  Result:= (Instance <> nil) and
           ((Instance.GetInterface(IUnknown, LUnknown)
             and (LUnknown.QueryInterface(IID, Temp) = 0)) or
            Instance.GetInterface(IID, Temp));
end;

测试:

procedure TForm4.Button3Click(Sender: TObject);
var
  Obj: TInterfacedObject;

begin
  Obj:= TInterfacedObject.Create;
  if MySupports(Obj, IUnknown) then
    ShowMessage('!!');
end;

希望它能在Delphi 3中工作

Write your own implementation of "Supports" function. In Delphi 2009 you can use

function MySupports(const Instance: TObject; const IID: TGUID): Boolean;
var
  Temp: IInterface;
  LUnknown: IUnknown;
begin
  Result:= (Instance <> nil) and
           ((Instance.GetInterface(IUnknown, LUnknown)
             and (LUnknown.QueryInterface(IID, Temp) = 0)) or
            Instance.GetInterface(IID, Temp));
end;

Test:

procedure TForm4.Button3Click(Sender: TObject);
var
  Obj: TInterfacedObject;

begin
  Obj:= TInterfacedObject.Create;
  if MySupports(Obj, IUnknown) then
    ShowMessage('!!');
end;

Hope it will work in Delphi 3

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文