title: How can I programmatically save event handler and then set it in C++ Builder?
body: <p>I need to temporary remove TFrame's OnExit and OnEnter events, so I'm trying to do following:</p>
  
  <p>declare FEnterHandler and FExit Handler:</p>
  
  <pre><code>private:
      // ...
      TControl *FParentControl;
      (__fastcall *(__closure)(TObject*))(TObject*) FEnterHandler;
      (__fastcall *(__closure)(TObject*))(TObject*) FExitHandler;
      // ...
  </code></pre>
  
  <p>and I intended to use them as typed downhere, but compilation failed on declaration.</p>
  
  <pre><code>__fastcall TProgressForm::TProgressForm(TComponent *O, TControl *PC)
      : TForm(O), FMapProgressData()
  {
      FParentControl = PC;
      if (FParentControl)
      {
          TFrame *frame = dynamic_cast&lt;TFrame*&gt;(FParentControl);
          if (frame)
          {
              FEnterHandler = frame-&gt;OnEnter;
              FExitHandler = frame-&gt;OnExit;
              frame-&gt;OnEnter = 0;
              frame-&gt;OnExit = 0;
          }
          FParentControl-&gt;Enabled = false;
      }
  }
  //-------------------------------------------------------------------------
  __fastcall TProgressForm::~TProgressForm()
  {
      if (FParentControl)
      {
          FParentControl-&gt;Enabled = true;
          TFrame *frame = dynamic_cast&lt;TFrame*&gt;(FParentControl);
          if (frame)
          {
              frame-&gt;OnEnter = FEnterHandler;
              frame-&gt;OnExit = FExitHandler;
          }
      }
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>