我有一个自定义控件,我试图定义一个OnMouseMoveFunction。本质上,控件用作搜索栏,由带有子自定义TGrid
控件的编辑框组成,用于显示结果。我已经为TGrid
处理了几个鼠标事件,但是当我尝试实现OnMouseMove时,当我尝试设置TGrid
OnMouseMove方法时,我收到以下错误:
E2034 Cannot convert 'void (_fastcall * (_closure )(TMouseMoveEvent))(TMouseMoveEvent)' to 'TMouseMoveEvent'
以下是定义函数的头文件:
void __fastcall GridMouseMove( TMouseMoveEvent * MouseEvent );
以下是控件CPP文件中的实际功能:
void __fastcall TFmSearchBar::GridMouseMove( TMouseMoveEvent * MouseEvent )
{
//handle event here
}
到目前为止,一切都会编译得很好。但是,当我将TGrid
的OnMouseMoveEvent处理程序分配给我指定的方法时,我收到了错误。
void __fastcall TFmSearchBar::SetGridProperties()
{
FGrid->OnKeyDown = GridKeyDown;
FGrid->OnClick = GridClick;
FGrid->OnMouseEnter = GridMouseEnter;
FGrid->OnMouseLeave = GridMouseLeave;
FGrid->OnMouseMove = GridMouseMove; //This line causes the error
}
我错过了什么导致这不构建?
答案 0 :(得分:1)
尝试使用IDE为TGrid生成的声明。
部首:
void __fastcall GridMouseMove(TObject *Sender, TShiftState Shift, float X, float Y);
cpp的实施:
void __fastcall TFmSearchBar::GridMouseMove(TObject *Sender, TShiftState Shift, float X,
float Y)
{
ShowMessage("123");
}
作业(相同):
void __fastcall TFmSearchBar::SetGridProperties()
{
...
FGrid->OnMouseMove = GridMouseMove; //This line causes the error
}
答案 1 :(得分:0)
原生TMouseMoveEvent
类型已经指针类型,因此请从声明中删除*
:
void __fastcall GridMouseMove( TMouseMoveEvent MouseEvent );
void __fastcall TFmSearchBar::GridMouseMove( TMouseMoveEvent MouseEvent )
{
//handle event here
}