Events are references to an object's method. Each event is explicitly typed with certain parameters. The most common type TNotifyEvent has the parameters (Sender: TObject) such as what you see on the OnClick event.
Other events however have other sets of parameters. OnMouseDown for example is a TMouseEvent which has the parameters (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer). You have to be sure the parameters of your procedure match that of the event type.
Here's essentially how everything is set up behind the scenes...
type
TNotifyEvent = procedure(Sender: TObject) of object;
TMouseEvent = procedure(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer) of object;
TControl = class(TComponent)
...
property OnClick: TNotifyEvent read FOnClick write FOnCLick;
property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown;
...
end;
In this case, you can also assign the same event handler to multiple different events of the same event type. For example, 5 different buttons with their OnClick event pointed to the same handler.
procedure TForm1.MyButtonClick(Sender: TObject);
begin
//Do Something...
end;
procedure TForm1.MyButtonMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//Do Something...
end;
Button1.OnClick := MyButtonClick;
Button2.OnClick := MyButtonClick;
Button3.OnClick := MyButtonClick;
Button4.OnClick := MyButtonClick;
Button5.OnClick := MyButtonClick;
Button1.OnMouseDown := MyButtonMouseDown;
Button2.OnMouseDown := MyButtonMouseDown;
Button3.OnMouseDown := MyButtonMouseDown;
Button4.OnMouseDown := MyButtonMouseDown;
Button5.OnMouseDown := MyButtonMouseDown;
If you want both of these events to do the same thing, you cannot assign the same event handler to events of different types, because they have different parameters. In that case, you will need to make both event handlers redirect to the same thing. Using the example, above, where you see //Do Something... in both places you would do the same exact thing. However, don't simply copy the code. Just make yet a third procedure, and make both event handlers call that one procedure.
procedure TForm1.MyButtonClick(Sender: TObject);
begin
DoSomething;
end;
procedure TForm1.MyButtonMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
DoSomething;
end;
procedure TForm1.DoSomething;
begin
//Do Something...
end;
On the other hand, the above example would make no sense in the real world though, because that would result in the same procedure being called twice for every button click. It's merely to demonstrate how to accomplish what you're trying to do using your example in your question.