0

How can I disable the mouse wheel scroll on a FMX TComboBox when hovering over it? I've tried overriding the MouseWheel method without any luck. I'm most likely doing it wrong as I'm not experienced with overriding. REF: MouseWheel

I've gone ahead and removed Inherited:

type
  TComboBoxOverride = class(TComboBox)
    procedure MouseWheel(Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean); override;
  end;

// I've tried changing the control on the class overriding the method. No luck
cbbServerMap: TComboBoxOverride;

{ TComboBoxOverride }

procedure TComboBoxOverride.MouseWheel(Shift: TShiftState; WheelDelta: Integer;
  var Handled: Boolean);
begin
  Handled := True;
end;

I've found the following SO post for VCL and DevEx but I'm struggling to convert it to FMX, Ref: How to suppress mouse wheel in TcxComboBox

When setting a breakpoint on the TCustomComboBox.MouseWheel method I can see that it ignores my override.

Adriaan
  • 806
  • 7
  • 24
  • 2
    Set Handled to True. – Ron Maupin Apr 27 '21 at 22:30
  • Unfortunately this does nothing. – Adriaan Apr 28 '21 at 07:01
  • The only way your override would be ignored is if your combo box control is not actually of type `TComboBoxOverride`. Are you sure that class in the fmx file is correct? Code you presented here should work, there is something else going on. – Dalija Prasnikar Apr 28 '21 at 12:28
  • I'm pretty sure its correct. I manually set it and then when I hit save the IDE asks me if I want to convert it back to TComboBox and I say no leaving it at the override. Can anyone preproduce this? – Adriaan May 03 '21 at 14:20

2 Answers2

1

In the OnMouseWheel event, simply put Abort;.

For example:

procedure TfrmMinorInjury.cboDischargetypeMouseWheel(Sender: TObject;
  Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean);
begin
  Abort;
end;
Anton Menshov
  • 2,266
  • 14
  • 34
  • 55
MarkoZaaz
  • 48
  • 3
0

I solved the same task but for memos in scrollbox.
My solution is

  1. handle mouse wheel in scrollbox.OnMouseWheel. Set Handle := true there.
  2. call directly scrollbox.OnMouseWheel in memo's OnMouseWheel
  • Can you please explain what you meant by calling the onMouseWheel event directly? I've tried `cbb1.OnMouseWheel(cbb1, [], 0, Handled);` right after Setting Handled to true however it seems to crash the application as it loops – Adriaan Aug 23 '21 at 18:17
  • you have to call parent's handler not self ``` procedure TForm1.Memo1OnMouseWheel(.....); begin scrollBox1.OnmouseWheel(.....); end; ``` – Vladimir Krapotkin Sep 02 '21 at 07:32