0

使用 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))'

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

4

1 回答 1

0

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

我将函数定义更改为:

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

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

于 2022-02-23T15:33:03.350 回答