接口 笔记

1.接口的继承者必须实现所有定义的接口函数或者方法

  IMyInterface1 = interface(IInterface)
    ['{63E072DF-B81E-4734-B3CB-3C23C7FDA8EA}']
    function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
    function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;
    procedure ShowMSG;
  end;

如果TMyInterface = class(TObject, IMyInterface1)

则在类TMyInterface 中许实现所有的QueryInterface,_AddRef,_Release,ShowMSG。

2.当继承多个接口的时候,如果有同样的函数名称,可以通过不同的名称进行区分

  IMyInterface1 = interface(IInterface)
    ['{63E072DF-B81E-4734-B3CB-3C23C7FDA8EA}']
    function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
    function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;
    procedure ShowMSG;
  end;

  IMyInterface2 = interface(IInterface)
    ['{9DF6FD12-E8FB-4500-9E43-36C6E769F199}']       
    function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
    function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;
    procedure ShowMSG;
  end;

  TMyInterface = class(TObject, IMyInterface1, IMyInterface2)
  private
    FRefCount: Integer;
    FMsg: string;
  public
    procedure IMyInterface1.ShowMSG = ShowMSG1;
    procedure IMyInterface2.ShowMSG = ShowMSG2;
    function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
    function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;
    procedure ShowMSG1;
    procedure ShowMSG2;
  end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值