pmcgee

C++Builder method pointers (VCL)

May 2nd, 2021 (edited)
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1A.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. //#include <Vcl.ExtCtrls.hpp>
  9. //#include <Vcl.ComCtrls.hpp>
  10. #include <Vcl.Dialogs.hpp>
  11. #include <map>
  12. // *pragma push explicit rcti
  13. #pragma explicit_rtti methods (__published, public) properties (__published, public)
  14.  
  15. class TTestClass : public TObject {
  16.     String  FName;
  17.  
  18.     public :
  19.         __property
  20.         String  Name          =     { read = FName };
  21.         void    DoGetRequest  ()    { ShowMessage( __FUNC__ ); }
  22.         void    DoPostRequest ()    { ShowMessage( __FUNC__ ); }
  23. };
  24.  
  25. typedef void (TTestClass::* TResourceFunc)();
  26. typedef std::map <String,   TResourceFunc>     TResourceFuncsList;
  27.  
  28. void    f( TTestClass* tc, TResourceFunc rf )  {  (tc->*rf)();  }
  29.  
  30. TForm1* Form1;
  31.  
  32. __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)  { }
  33.  
  34.  
  35. void __fastcall TForm1::Button1Click(TObject *Sender)  {
  36.  
  37.     TTestClass* tc = new TTestClass();
  38.     //f( tc, &TTestClass::DoGetRequest  );
  39.     //f( tc, &TTestClass::DoPostRequest );
  40.  
  41.     TResourceFuncsList rfl { {"Get Request",  &TTestClass::DoGetRequest},
  42.                              {"Post Request", &TTestClass::DoPostRequest}
  43.                            };
  44.     f( tc, rfl["Get Request" ] );
  45.     f( tc, rfl["Post Request"] );
  46. }
  47.  
  48. // --- --- --- --- ---
  49.  
  50. /*
  51. #ifndef Unit1AH
  52. #define Unit1AH
  53. //---------------------------------------------------------------------------
  54. #include <System.Classes.hpp>
  55. #include <Vcl.Controls.hpp>
  56. #include <Vcl.StdCtrls.hpp>
  57. #include <Vcl.Forms.hpp>
  58.  
  59. class TForm1 : public TForm
  60. {
  61.   __published:  // IDE-managed Components
  62.       TButton*         Button1;
  63.       void __fastcall  Button1Click (TObject*   Sender);
  64.   public:       // User declarations
  65.            __fastcall  TForm1       (TComponent* Owner);
  66. };
  67. extern PACKAGE TForm1* Form1;
  68. #endif
  69. */
  70.  
Add Comment
Please, Sign In to add comment