日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

教程-Supports判断接口(Instance)是否支持

發布時間:2023/12/25 综合教程 28 生活家
生活随笔 收集整理的這篇文章主要介紹了 教程-Supports判断接口(Instance)是否支持 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
 1 function TCommandEnabledController.GetCommandVisible(const ACommandName: string): Boolean;
 2 var
 3   I: Integer;
 4   //定義接口接收者
 5   oCommandVisibleExecutor: ICommandVisibleExecutor;
 6 begin
 7   Result := True;
 8   for I := 0 to FExecutors.Count - 1 do
 9   begin
10     //判斷接口是否支持
11     if Supports(FExecutors[I], ICommandVisibleExecutor, oCommandVisibleExecutor) then
12     begin
13       //使用接口接收者
14       if not oCommandVisibleExecutor.CommandVisible(ACommandName) then
15       begin
16         Result := False;
17         Break;
18       end;
19     end;
20   end;
21 end;

delphi中的函數Supports位于SysUtils單元

定義如下:

1 { Interface support routines }
2 
3 function Supports(const Instance: IInterface; const IID: TGUID; out Intf): Boolean; overload;
4 function Supports(const Instance: TObject; const IID: TGUID; out Intf): Boolean; overload;
5 function Supports(const Instance: IInterface; const IID: TGUID): Boolean; overload;
6 function Supports(const Instance: TObject; const IID: TGUID): Boolean; overload;
7 function Supports(const AClass: TClass; const IID: TGUID): Boolean; overload;

實現如下:

 1 { Interface support routines }
 2 
 3 function Supports(const Instance: IInterface; const IID: TGUID; out Intf): Boolean;
 4 begin
 5   Result := (Instance <> nil) and (Instance.QueryInterface(IID, Intf) = 0);
 6 end;
 7 
 8 function Supports(const Instance: TObject; const IID: TGUID; out Intf): Boolean;
 9 var
10   LUnknown: IUnknown;
11 begin
12   Result := (Instance <> nil) and
13             ((Instance.GetInterface(IUnknown, LUnknown) and Supports(LUnknown, IID, Intf)) or
14              Instance.GetInterface(IID, Intf));
15 end;
16 
17 function Supports(const Instance: IInterface; const IID: TGUID): Boolean;
18 var
19   Temp: IInterface;
20 begin
21   Result := Supports(Instance, IID, Temp);
22 end;
23 
24 function Supports(const Instance: TObject; const IID: TGUID): Boolean;
25 var
26   Temp: IInterface;
27 begin
28   Result := Supports(Instance, IID, Temp);
29 end;
30 
31 function Supports(const AClass: TClass; const IID: TGUID): Boolean;
32 begin
33   Result := AClass.GetInterfaceEntry(IID) <> nil;
34 end;

總結

以上是生活随笔為你收集整理的教程-Supports判断接口(Instance)是否支持的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。