[Lazarus] TMouseButton

Martin lazarus at mfriebe.de
Wed Apr 7 16:01:34 CEST 2010


On 07/04/2010 14:46, Kjow wrote:
> Hi all,
>
> I need to create an "advanced" function that manages mouse events, so
> I need to know when/which a button is pressed and so, when no button
> is pressed.
> I saw that in TMouseButton (row 142 of Controls unit) there isn't
> mbNone, so I simply edited that row:
>
> TMouseButton = (mbNone, mbLeft, mbRight, mbMiddle, mbExtra1, mbExtra2);
>
> Now I can see when no buttons are pressed; I simply manage it with
>
> MouseButtonPressed:=Button; //OnMouseDown
>
> MouseButtonPressed:=mbNone; //OnMouseUp
>
> Now the question: there is a better way to do this whitout modify the
> Lazarus source code? It is a bug/missing feature or this is a feature?
>    

I wouldn't recommend that change. Some units define
   const  Foo = Array [TMouseButton] of String = (list of names for values);

Those will break, because the count of the enum changed.

Create a set

type
   TMouseButtons = set of  TMouseButton ;
var
   MouseButtonPressed: TMouseButtons;

MouseButtonPressed := [];
MouseButtonPressed := [mbLeft];
MouseButtonPressed := [mbLeft, mbRight];

and so on




More information about the Lazarus mailing list