在运行时分配 TScrollBox 事件 - 不兼容的类型

Assigning TScrollBox event during runtime - incompatible types

使用 RAD Studio 10.4.2:

我在运行时创建TScrollBox

TScrollBox* sb = new TScrollBox(this);
sb->Parent = this;
sb->Align = alClient;
sb->AlignWithMargins = true;
sb->Margins->SetBounds(3,3,3,3);
sb->BorderStyle = bsNone;
sb->VertScrollBar->Smooth = true;
sb->VertScrollBar->Tracking = true;
sb->ParentBackground = true;
sb->OnMouseWheel = ScrollBox1MouseWheel; // Error here

我想给它分配OnMouseWheel事件:

void __fastcall TForm1::ScrollBox1MouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
TPoint &MousePos, bool &Handled)
{
// Some code here
}

鼠标滚轮事件就是我把它放在窗体上双击生成上面的事件代码得到的。

虽然错误是:

[bcc32c Error] assigning to 'Vcl::Controls::TMouseWheelEvent' (aka 'void ((__closure *))(System::TObject *, System::Classes::TShiftState, int, const System::Types::TPoint &, bool &) __attribute__((fastcall))') from incompatible type 'void (__closure *)(System::TObject *, System::Classes::TShiftState, int, System::Types::TPoint &, bool &) __attribute__((fastcall))'

那我该如何分配事件,我需要以某种方式投射它吗?

发布后立即自己解决了,所以我分享解决方案:

我将函数定义更改为:

void __fastcall TForm1::ScrollBox1MouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
const TPoint &MousePos, bool &Handled) // -> added const here
{
// Some code here
}

出于某种原因 10.4.2 GUI 在 TPoint 中生成没有 const 的函数,当您从对象检查器中双击时,但它期望在运行时分配它,所以当 const 添加它编译就好了。