Search code examples
androiddelphidelphi-xe5onmousedownonmouseup

Do OnMouseDown and OnMouseUp only work as a pair?


My application has a lot of TRectangle's acting as keys of a keyboard. When one is clicked you hear a sound. This is done by handling the OnMouseDown and OnMouseUp event. OnMouseDown: send a sound and OnMouseUp: switch it off. All works fine, except for one thing.

On Android I can use several fingers to press several keys. When one OnMouseDown has been processed, no other OnMouseDown Events will be processed until an OnMouseUp event has been processed. It needn't be the OnMouseUp of the key that blocked the other OnMouseDown, it may be any OnMouseUp event. Sample code:

procedure TKeyBoard.note_down (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
var
   key: TKey;
begin
   key := Sender as TKey;
   logd ('Entering OnMouseDown event handler: %d', [key.Note]);
   PutShort ($90, key.Note, 127);
   logd ('Exiting OnMouseDown event handler: %d', [key.Note]);
end; // note_down //

procedure TKeyBoard.note_up (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
var
   key: TKey;
begin
   key := Sender as TKey;
   logd ('Entering OnMouseUp event handler: %d', [key.Note]);
   PutShort ($80, Key.Note, 127);
   logd ('Exiting OnMouseUp event handler: %d', [key.Note]);
end; // note_up //
...
Rectangle [i].OnMouseDown := note_down;
Rectangle [i].OnMouseUp   := note_up;

Where the note_down and note_up routines are entered and exited immediately according to the debug code. Is it right to assume that when an OnMouseDown has been processed, no OnMouseDown's can be processed until an OnMouseUp has been handled? If so, is there a workaround?


Solution

  • Give OnMouseEnter a shot for mobile. I'm working on a project with lots of rectangles and in my code I have

    {$ifdef MSWINDOWS}
    lRect.OnClick := ClickEvent;
    {$else}
    lRect.OnMouseEnter := ClickEvent;
    {$endif}
    

    What this allows me to do is drag my finger across a grid of rectangles and have it call my ClickEvent for each rectangle I pass over.