我需要访问
VScrollBar
和 TListBox
中 TComboBox
的 TComboEdit
,以便找到其中的 TThumb
(使用 EnumControls
方法)并设置自定义 OnMouseEnter
, OnMouseLeave
、OnMouseDown
和 OnMouseUp
事件,如下所示:
class TScrollThumb : public TCppInterfacedObject<TFunc__2<TControl*, TEnumControlsResult>> {
public:
TEnumControlsResult __fastcall Invoke(TControl* Control) {
if (Control->ClassNameIs("TThumb")) {
Control->OnMouseEnter = MouseEnter;
Control->OnMouseLeave = MouseLeave;
Control->OnMouseDown = MouseDown;
Control->OnMouseUp = MouseUp;
return TEnumControlsResult::Stop;
}
return TEnumControlsResult::Continue;
}
};
if (ComboBox->ListBox->VScrollBar) ComboBox->ListBox->VScrollBar->EnumControls(new TScrollThumb);
// TScrollBar *scrollbar = ComboBox->ListBox->GetVScrollBar();
// if (scrollbar) scrollBar->EnumControls(new TScrollThumb);
VScrollBar
属性是Fmx::Layouts::TCustomScrollBox
的受保护成员,而GetVScrollBar()
是Fmx::Layouts::TCustomScrollBox
的私有成员,但即使将它们公开也没有任何作用,我仍然无法访问VScrollBar
。
同样的方法对于
TThumb
内的 TVertScrollBox
非常有效。这种情况我能做什么?
我自己似乎找到了解决办法。有点棘手,但它就像一个魅力。所以我就按原样将其发布在这里:
class TScrollThumb : public TCppInterfacedObject<TFunc__2<TControl*, TEnumControlsResult>> {
public:
TEnumControlsResult __fastcall Invoke(TControl* Control) {
if (Control->ClassNameIs("TThumb")) {
Control->OnMouseEnter = MouseEnter;
Control->OnMouseLeave = MouseLeave;
Control->OnMouseDown = MouseDown;
Control->OnMouseUp = MouseUp;
return TEnumControlsResult::Stop;
}
return TEnumControlsResult::Continue;
}
};
void __fastcall ListBoxMouseEnter(TObject *Sender) {
((TControl*)Sender)->EnumControls(new TScrollThumb);
// The tricky part: working with a ListBox inside of its own event handler;
}
ComboBox->ListBox->OnMouseEnter = ListBoxMouseEnter;
// Assign an auxiliary event handler to a ListBox that has already been displayed;