zoukankan      html  css  js  c++  java
  • Delphi接口示例代码

      
      IMyInterface = interface(IInterface)
        ['{63E072DF-B81E-4734-B3CB-3C23C7FDA8EA}']
        function F1 : Integer; stdcall;
      end;
    
      TFooBar = class(TBaseProperty, IMyInterface)
        function F1 : Integer; virtual; stdcall;
      protected
        FRefCount: Integer;
        function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
        function _AddRef: Integer; stdcall;
        function _Release: Integer; stdcall;
      end;
    
      TFooBar1 = class(TFooBar)
        function F1: Integer;  override; stdcall;
      end;
    

      

    procedure TForm1.Button2Click(Sender: TObject);
    var
      a: TFooBar;
      dd: IMyInterface;
    begin
      a := TFooBar1.Create;
    
      if a.GetInterface(IMyInterface, dd) then
        Memo1.Lines.Add(IntToStr(dd.F1));
    
    end;
    

      

    function TFooBar.QueryInterface(const IID: TGUID; out Obj): HResult;
    const
      E_NOINTERFACE = HResult($80004002);
    begin
      if GetInterface(IID, Obj) then
        Result := 0
      else
        Result := E_NOINTERFACE;
    end;
    
    function TFooBar._AddRef: Integer;
    begin
      INC(FRefCount);
    //  ShowMessage(Format('Increase reference count to %d.', [FRefCount]));
      result:=FRefCount;
    end;
    
    function TFooBar._Release: Integer;
    begin
     DEC(FRefCount);
      if FRefCount <> 0 then
    //    ShowMessage(Format('Decrease reference count to %d.', [FRefCount]))
      else begin
        Destroy;
    //    ShowMessage('Decrease reference count to 0, and destroy the object.');
      end;
      result:=FRefCount;
    end;
    

      

  • 相关阅读:
    gojs常用API (中文文档)
    webpack的安装
    win10如何将wps设置成默认应用
    gojs常用API-画布操作
    Access中替代case when的方法 .
    C++ 11 中的右值引用
    形参前的&&啥意思?
    【C语言学习笔记】字符串拼接的3种方法 .
    java项目打jar包
    教你用DrawLayout 实现Android 侧滑菜单
  • 原文地址:https://www.cnblogs.com/tsolarboy/p/9442645.html
Copyright © 2011-2022 走看看