TCppInterfacedObject - C++ Builder

C++ Builder 参考手册 ➙ System ➙ TCppInterfacedObject


System::TCppInterfacedObject 是基于 TInterfacedObject 派生出来的类模板,用于实现 IInterface (IUnknown) 接口,在使用不支持 lambda 表达式的编译器或不想用 lambda 表达式的时候,采用这个模板来实现 Delphi 的匿名函数

  • System::TCppInterfacedObject 简介
  • System::TCppInterfacedObject 成员

一. System::TCppInterfacedObject 简介

System::TCppInterfacedObject 是

  • 继承关系:
    System::TObject
    ⠀╙ System::TInterfacedObject
    ⠀⠀⠀┗ TCppInterfacedObject
  • 头文件:#include
  • 命名空间:System
  • 是基于 TInterfacedObject 派生出来的类模板,用于实现 IInterface (IUnknown) 接口,在使用不支持 lambda 表达式的编译器或不想用 lambda 表达式的时候,采用这个模板来实现 Delphi 的匿名函数;
  • 新版 C++ Builder 在使用 Delphi 的匿名函数的时候,通常使用 lambda 表达式,请参考 _di_TProc、_di_TProc__1 和 TThread::CreateAnonymousThread 的描述和例子;
  • 老版本 C++ Builder 在使用 Delphi 的匿名函数的时候,例如 TProc、TProc__1、TFunc__1 等类型时,使用这个模板来实现 (当然新版本也可以用这个方法,如果不嫌麻烦):
    Delphi 类型 TProc:C++ 使用 TCppInterfacedObject
    Delphi 类型 TFunc__1:C++ 使用 TCppInterfacedObject
    ……
  • 由于第一个模板参数一般都是使用纯虚类 TProc 等,这个模板继承了模板参数,所以子类必须实现 Invoke 方法,Invoke 的参数与第一个模板参数的纯虚函数 Invoke 必须相同
  • 模板定义:
template 
class TCppInterfacedObject: public TInterfacedObject,
                            public INTF1, public INTF2, public INTF3
{
protected:
    typedef TCppInterfacedObject _COM_CLASS;
public:
    ULONG   __stdcall AddRef()  { return TInterfacedObject::_AddRef();  }
    ULONG   __stdcall Release() { return TInterfacedObject::_Release(); }
    HRESULT __stdcall QueryInterface(REFIID iid, void** p) { return TInterfacedObject::QueryInterface(iid, p); }
};

二. System::TCppInterfacedObject 成员

1. System::TCppInterfacedObject 属性

属性 类型 说明
TInterfacedObject:: 从 System::TInterfacedObject 继承过来的
public:    
RefCount int 引用计数

2. System::TCppInterfacedObject 方法

成员函数 说明
public:  
AddRef 增加引用计数
QueryInterface 返回当前组件所支持的 COM 接口的引用
Release 减少引用计数 / 销毁对象
TInterfacedObject:: 从 System::TInterfacedObject 继承过来的
public: 从 System::TInterfacedObject 继承过来的
_AddRef 增加引用计数
AfterConstruction 在构造函数执行结束时调用
BeforeDestruction 在析构函数执行之前时调用
NewInstance 给实例分配内存,并且返回新的实例的地址
operator _di_IInterface 类型转换操作符,转为 _di_IInterface 类型
_Release 减少引用计数 / 销毁对象
TObject:: 从 System::TObject 继承过来的
public: 从 System::TObject 继承过来的
ClassInfo 返回运行时类型信息表 (RTTI table)
ClassName 获取类名,不包含命名空间的类名字符串
ClassNameIs 判断类名是否为参数指定的字符串
ClassParent 返回父类的类型信息
ClassType 返回类的类型信息
CleanupInstance 清除长字符串、Variants、接口变量等
DefaultHandler 默认的消息处理
Dispatch 处理消息的函数
DisposeOf 强制销毁对象
Equals 比较当前对象和 Obj 对象是否相同
FieldAddress 通过成员名称返回成员的地址
Free 销毁对象 (Delphi)
FreeInstance 释放 NewInstance 分配的内存
GetHashCode 返回对象的 hash 值
GetInterface 获取指定的接口
GetInterfaceEntry 获取接口项目
GetInterfaceTable 获取接口表
InheritsFrom 当前对象的类是否从 AClass 继承过来的
InitInstance 初始化成员,给他们清零
InstanceSize 返回给实例数据分配内存需要多少字节数
MethodAddress 通过名称返方法的地址
MethodName 通过方法的地址返回名称
QualifiedClassName 返回包含命名空间的类名
SafeCallException 处理异常的函数
ToString 转为字符串
UnitName 返回类所在的命名空间
UnitScope 返回类所在的命名空间

3. System::TCppInterfacedObject 类型成员

类型 说明
protected:  
_COM_CLASS 就是这个模板类型本身带上模板参数的类型

4. System::TCppInterfacedObject 数据成员

数据 类型 说明
TInterfacedObject:: 从 System::TInterfacedObject 继承过来的
protected: 从 System::TInterfacedObject 继承过来的
FRefCount int 用于保存引用计数

相关:

  • TThread::CreateAnonymousThread
  • System::Sysutils::_di_TFunc__1
  • System::Sysutils::_di_TFunc__2
  • System::Sysutils::_di_TFunc__3
  • System::Sysutils::_di_TFunc__4
  • System::Sysutils::_di_TFunc__5
  • System::Sysutils::_di_TPredicate__1
  • System::Sysutils::_di_TProc
  • System::Sysutils::_di_TProc__1
  • System::Sysutils::_di_TProc__2
  • System::Sysutils::_di_TProc__3
  • System::Sysutils::_di_TProc__4
  • System::IInterface
  • System::_di_IInterface
  • System::TInterfacedObject
  • System::Classes::TComponent
  • System::Classes::TInterfacedPersistent
  • System::Classes::TPersistent
  • System::Syncobjs::TSynchroObject
  • System::TObject
  • VCL 类继承关系

C++ Builder 参考手册 ➙ System ➙ TCppInterfacedObject

你可能感兴趣的:(TCppInterfacedObject - C++ Builder)