Since I'm inheriting from other class, as @rvk mention in previous post, I'd rather override some procedure like MouseWheelown (as I did with Click and Paint) but I have no clue how to approach it. Any piece of advice?
Ok, I'm behind my computer... so...
Here are the stept to take if you want to ASSIGN the
OnMouseWheel event.
Do note: If you do this, the one using the component CAN'T assign it's own.
That's why the overriding the
DoMouseWheel might be a better option because then you can leave the
OnMouseWheel intact for the user.
Put your cursor on the text .OnMouseWheel
Press Alt + Arrow up
If you are at a line with "property OnMouseWheel"
Press Alt + Arrow up again
Now if you are at the line with "property OnMouseWheel: TMouseWheelEvent"
you are at the correct place.
Put the cursor on TMouseWheelEvent
Press Alt + Arrow up
Now you see the definition of the Wheel event
TMouseWheelEvent = procedure(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean) of Object;
So if you want to assign the .OnMouseWheel to a procedure you need to make a procedure like:
procedure MyMouseWheelProc(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean) of Object;
And assign it via (depending on fpc or delphi mode)
Self.OnMouseWheel := @MyMouseWheelProc;
// or
Self.OnMouseWheel := MyMouseWheelProc;
~~
Now for the
overriding of the
DoMouseWheel.
In the source where you got the TMouseWheelEvent you can search for "MouseWheel("
You'll find that there is a function DoMouseWheel. You want to override that one.
Copy that line to your component class and create a override function (change the virtual to override).
protected
function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override; // <- OVERRIDE
//....
function MyComponent.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean;
begin
Result := inherited; // <--- don't forget this. This is the old DoMouseWheel so you probably want to keep that functionality
// that old DoMouseWheel also calls the user-assigned OnMouseWheel
// now do your thing
end;
(all this is typed without checking so I hope it's correct.)