动态创建的ComboBox控件,添加OnDrawItem事件是报错
[BCC32 Error] test.cpp(43): E2034 Cannot convert 'void (_fastcall * (_closure )(TWinControl *,int,TRect &,TOwnerDrawState))(TWinControl *,int,TRect &,TOwnerDrawState)' to 'TDrawItemEvent'
Full parser context
test.cpp(32): parsing: void _fastcall TForm1::Button1Click(TObject *)
请教一下,我动态的创建了一个ComboBox控件,添加了OnDrawItem事件,结果报错,找不到原因,Help
[解决办法]
TRect 加一个const 就好了
class TForm1 : public TForm{__published: // IDE-managed Components TComboBox *ComboBox1; void __fastcall ComboBox1DrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State); void __fastcall myComboBox1DrawItem(TWinControl *Control, int Index, const TRect &Rect, TOwnerDrawState State); void __fastcall FormCreate(TObject *Sender);private: // User declarationsTComboBox *ComboBox2;public: // User declarations __fastcall TForm1(TComponent* Owner);};
[解决办法]
VCL组件的事件处理函数,声明定义最好与事件的处理函数原型保持一致。