By logic, a MouseDown
event has to be followed by (paired) with a MouseUp
event. It's the way the mouse physically operates.
The mouse button is pressed (which means it becomes "down"). It can't be pressed again until it is released and goes back to the "up" state. (There is no such thing as a "mouse partially down", "mouse a little further down", "mouse down even a little bit more" state; the mouse button is either pressed ("down") or unpresssed ("up").
The only reasonable progression is MouseDown
followed by a corresponding (paired) MouseUp
. The Sender
for both messages may not be the same control - the mouse can become pressed over one control, moved while the button remains down, and then released over a different control (or even outside the application itself) - but the sequence must be "down, then up" in that order.
Here's a quick way to demonstrate that behavior and logic.
- Create a new VCL Forms application (or FMX application - replace
TShape
with TMemo
or any other control with an OnMouseDown
and OnMouseUp
event in the following steps)
- Drop a
TShape
on the left side of the form.
- Drop a
TLabel
to the right of that TShape
Click on the TShape
, switch to the Events tab in the Object Inspector, and add the following event handlers for the Shape1.OnMouseDown
and Shape1.OnMouseUp
events:
procedure TForm1.Shape1MouseDown(Sender: TObject);
begin
Label1.Caption := 'Mouse down';
Label1.Update;
end;
procedure TForm1.Shape1MouseUp(Sender: TObject);
begin
Label1.Caption := 'Mouse up';
Label1.Update;
end;
Run the app. Put the mouse over Shape1
and press the button. Notice the text of the label, which displays "Mouse down". Release it and the caption of the label changes to "Mouse up".
Experiment with pressing the mouse button over the shape to set the label's caption to "Mouse down" and then moving the mouse to various locations and releasing the button, watching the label change to "Mouse up" each time the button is released regardless of the location of the mouse pointer.