是否有非引用计数的基类,如TInterfacedObject? [英] Is there a non-reference-counted base class like TInterfacedObject?

查看:234
本文介绍了是否有非引用计数的基类,如TInterfacedObject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个基类,如 TInterfacedObject ,但没有引用计数(所以一种 TNonRefCountedInterfacedObject )。

I need a base class like TInterfacedObject but without reference counting (so a kind of TNonRefCountedInterfacedObject).

这实际上是第n次我需要这样一个类,不知何故,我总是最后一次又一次地写我自己的书写(阅读:复制和粘贴)。我不能相信没有可以使用的官方基类。

This actually is the nth time I need such a class and somehow I always end up writing (read: copy and pasting) my own again and again. I cannot believe that there is no "official" base class I can use.

RTL中是否有基类实现 IInterface 但是没有引用计数,我可以从哪个派生我的类?

Is there a base class somewhere in the RTL implementing IInterface but without reference counting which I can derive my classes from?

推荐答案

在单位通用。默认情况下定义了一个类别TSingletonImplementation。提供德尔福2009及以上版本。

In the unit Generics.Defaults there is a class TSingletonImplementation defined. Available in Delphi 2009 and above.

  // A non-reference-counted IInterface implementation.
  TSingletonImplementation = class(TObject, IInterface)
  protected
    function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
    function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;
  end;

这篇关于是否有非引用计数的基类,如TInterfacedObject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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