2017-08-15 3 views
0

どのように使っても、TScrollBoxを動的に作成してOnMouseWheelEventハンドラを割り当てることはできません。私は、次のコンパイラエラーを取得する:OnMouseWheelEventハンドラのC++ Builder TMouseWheelEventコンパイラエラー

E2034 Cannot convert 'void (_fastcall * (_closure)(TObject *,TShiftState,int,TPoint &,bool &))(TObject *,TShiftState,int,TPoint &,bool &)' to 'TMouseWheelEvent'

私の宣言は(私の知る限り)正しい:

.... 
TScrollBox *sb = new TScrollBox(funnelCharts); 
sb->Top = 5000; 
sb->Parent = funnelCharts; 
sb->Align = alClient; 
sb->Height = funnelCharts->ClientHeight; 
sb->OnMouseWheel = scrollEvent; 
.... 

// -------------------------------------------------------------- 

void __fastcall TForm1::scrollEvent(TObject *Sender, TShiftState Shift, int WheelDelta, TPoint &MousePos, bool &Handled) 
{ 
    TScrollBox *scrollbox = dynamic_cast<TScrollBox*>(Sender); 
    if (scrollbox) 
    { 
     for (int i = 1; i < Mouse->WheelScrollLines; i++) 
     { 
      if (WheelDelta > 0) 
      { 
       scrollbox->Perform(WM_VSCROLL, SB_LINEUP, 0); 
      } 
      else 
      { 
       scrollbox->Perform(WM_VSCROLL, SB_LINEDOWN, 0); 
      } 
     } 
     scrollbox->Perform(WM_VSCROLL, SB_ENDSCROLL, 0); 
     Handled = true; 
    } 
} 

答えて

0

これはコンパイラエラー、ないリンカーであり、エラー。

TMouseWheelEventの実際の宣言をControls.hppに見てください。 scrollEvent()メソッドが実際に宣言されているものと一致しない場合は、エラーが発生しません。あなたは32ビットまたは64ビット、TMouseWheelEvent(具体的には、そのMousePosパラメータ)用にコンパイルされているかどうかに応じて

が異なっ宣言されています。

32ビット:

typedef void __fastcall (__closure *TMouseWheelEvent)(System::TObject* Sender, System::Classes::TShiftState Shift, int WheelDelta, const System::Types::TPoint &MousePos, bool &Handled); 

64ビット:

typedef void __fastcall (__closure *TMouseWheelEvent)(System::TObject* Sender, System::Classes::TShiftState Shift, int WheelDelta, System::Types::TPoint MousePos, bool &Handled); 

この理由は、BCC32とBCC64は、彼らが周りに8バイトの構造体のタイプ(TPointなど)を渡す方法が異なります。この違いは、エンバカデロのDocWikiに文書化されています。この違いによる影響を受け

Events with Structures or Sets of 5-8 Bytes Are Not Valid for BCC64

他のイベントタイプをTGetSiteInfoEventTMouseWheelUpDownEvent、そしてTContextPopupEventが含まれます。でもクリーナー、

class TForm1 : public TForm 
{ 
    ... 
    void __fastcall scrollEvent(
     TObject* Sender, TShiftState Shift, int WheelDelta, 
     #ifndef _WIN64 
     const TPoint &MousePos, 
     #else 
     TPoint MousePos, 
     #endif 
     bool &Handled); 
    ... 
}; 

... 

void __fastcall TForm1::scrollEvent(TObject* Sender, TShiftState Shift, int WheelDelta, 
    #ifndef _WIN64 
    const TPoint &MousePos, 
    #else 
    TPoint MousePos, 
    #endif 
    bool &Handled) 
{ 
    ... 
} 

または::

class TForm1 : public TForm 
{ 
    ... 
    #ifndef _WIN64 
    void __fastcall scrollEvent(TObject* Sender, TShiftState Shift, int WheelDelta, const TPoint &MousePos, bool &Handled); 
    #else 
    void __fastcall scrollEvent(TObject* Sender, TShiftState Shift, int WheelDelta, TPoint MousePos, bool &Handled); 
    #endif 
    ... 
}; 

... 

#ifndef _WIN64 
void __fastcall TForm1::scrollEvent(TObject* Sender, TShiftState Shift, int WheelDelta, const TPoint &MousePos, bool &Handled) 
#else 
void __fastcall TForm1::scrollEvent(TObject* Sender, TShiftState Shift, int WheelDelta, TPoint MousePos, bool &Handled) 
#endif 
{ 
    ... 
} 

をそれとも、少しクリーナーのアプローチを:

これを修正するには、文書化#ifdefにあなたのコードを持っています

#ifndef _WIN64 
#define SAFE_5TO8_PARAM(type, name) const type &name 
#else 
#define SAFE_5TO8_PARAM(type, name) type name 
#endif 

class TForm1 : public TForm 
{ 
    ... 
    void __fastcall scrollEvent(TObject* Sender, TShiftState Shift, int WheelDelta, SAFE_5TO8_PARAM(TPoint, MousePos), bool &Handled); 
    ... 
}; 

... 

void __fastcall TForm1::scrollEvent(TObject* Sender, TShiftState Shift, int WheelDelta, SAFE_5TO8_PARAM(TPoint, MousePos), bool &Handled) 
{ 
    ... 
} 
+0

だから私が欠けていたのはちょうどconstだった(32ビット用)。 ありがとうございます! –