教程-Supports判断接口(Instance)是否支持
2015-08-31 14:03
288 查看
function TCommandEnabledController.GetCommandVisible(const ACommandName: string): Boolean; var I: Integer; //定义接口接收者 oCommandVisibleExecutor: ICommandVisibleExecutor; begin Result := True; for I := 0 to FExecutors.Count - 1 do begin //判断接口是否支持 if Supports(FExecutors[I], ICommandVisibleExecutor, oCommandVisibleExecutor) then begin //使用接口接收者 if not oCommandVisibleExecutor.CommandVisible(ACommandName) then begin Result := False; Break; end; end; end; end;
delphi中的函数Supports位于SysUtils单元
定义如下:
{ Interface support routines } function Supports(const Instance: IInterface; const IID: TGUID; out Intf): Boolean; overload; function Supports(const Instance: TObject; const IID: TGUID; out Intf): Boolean; overload; function Supports(const Instance: IInterface; const IID: TGUID): Boolean; overload; function Supports(const Instance: TObject; const IID: TGUID): Boolean; overload; function Supports(const AClass: TClass; const IID: TGUID): Boolean; overload;
实现如下:
{ Interface support routines } function Supports(const Instance: IInterface; const IID: TGUID; out Intf): Boolean; begin Result := (Instance <> nil) and (Instance.QueryInterface(IID, Intf) = 0); end; function Supports(const Instance: TObject; const IID: TGUID; out Intf): Boolean; var LUnknown: IUnknown; begin Result := (Instance <> nil) and ((Instance.GetInterface(IUnknown, LUnknown) and Supports(LUnknown, IID, Intf)) or Instance.GetInterface(IID, Intf)); end; function Supports(const Instance: IInterface; const IID: TGUID): Boolean; var Temp: IInterface; begin Result := Supports(Instance, IID, Temp); end; function Supports(const Instance: TObject; const IID: TGUID): Boolean; var Temp: IInterface; begin Result := Supports(Instance, IID, Temp); end; function Supports(const AClass: TClass; const IID: TGUID): Boolean; begin Result := AClass.GetInterfaceEntry(IID) <> nil; end;
相关文章推荐
- 儿子/兄弟树
- 淘宝分享互联网用户的心理特征
- 一个ios不错的blog地址
- java数据库操作
- eclipse adt 和 android studio 的区别
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1)A,B
- 双网卡实现内外网络同时使用
- cocos2dx 玩转震动
- AngularJS小示例
- Tez-自定义DAG图
- UNIX网络编程卷一:调试工具 tcpdump lsof 总结
- [iOS]#Swift#OC+Swift混编
- 如果你快乐不是为我,那该有多么…………-----阿冬专栏
- 关于拟物化和扁平化的讨论---多研究些问题,少谈些主义
- 实现matlab直方图的网格填充
- Qt Creator的配置和开发初步测试
- IOMMU
- C#Linq技术中SelectMany(...)函数的内部实现的伪代码
- setAttribute,,,getAttribute,,,,
- GIT在Linux上的安装和使用简介