delphifiremonkeydelphi-10.4-sydney

How to disable FMX ComboBox Mouse Wheel scroll


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.


Solution

  • In the OnMouseWheel event, simply put Abort;.

    For example:

    procedure TfrmMinorInjury.cboDischargetypeMouseWheel(Sender: TObject;
      Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean);
    begin
      Abort;
    end;