zoukankan      html  css  js  c++  java
  • C++Builder XE7 中“匿名”方法实现

     1     class TMyProc : public TCppInterfacedObject<TThreadProcedure>
     2     {
     3     private:
     4         String p1;
     5         String p2;
     6     public:
     7         TMyProc(String V1, String V2): p1(V1), p2(V2) {};
     8         virtual void __fastcall Invoke(void)
     9         {
    10             Application->MessageBoxW(p1.c_str(), p2.c_str());
    11         }
    12     };
    13 
    14     TThread::Synchronize(TThread::CurrentThread, new TMyProc("A", "B"));

    相对于DELPHI来说有些麻烦,只能通过构造函数传参数。TCppInterfacedObject的定义如下:

     1 #if !defined(INTFOBJECT_IMPL_IUNKNOWN)
     2 #define INTFOBJECT_IMPL_IUNKNOWN(BASE) 
     3   ULONG   __stdcall AddRef() { return BASE::_AddRef();}  
     4   ULONG   __stdcall Release(){ return BASE::_Release();} 
     5   HRESULT __stdcall QueryInterface(REFIID iid, void** p){ return BASE::QueryInterface(iid, p);}
     6 #endif
     7 
     8   template <typename INTF1, typename INTF2=IUnknown, typename INTF3=IInterface>
     9   class TCppInterfacedObject: public TInterfacedObject,
    10                               public INTF1, public INTF2, public INTF3
    11   {
    12   protected:
    13      typedef TCppInterfacedObject<INTF1, INTF2, INTF3> _COM_CLASS;
    14   public:
    15      INTFOBJECT_IMPL_IUNKNOWN(TInterfacedObject);
    16   };
  • 相关阅读:
    vector容器
    CSS3文字与字体 text-overflow 与 word-wrap
    div 居中
    C# 邮件发送
    SD详解-销售过程
    js 常用
    finereport报表--动态格间运算 二
    finereport报表--动态格间运算 一
    CSS 渐变色
    CSS3 box-shadow 属性 紧跟在 -webkit-, -ms- 或 -moz-
  • 原文地址:https://www.cnblogs.com/Jiaojiawang/p/4295991.html
Copyright © 2011-2022 走看看