I'm having trouble regarding mouse down and up events, specifically with the TTreeView control. Delphi offers OnMouseDown and OnMouseUp events for handling mouse events, but when testing them I've found them to be quite buggy. For example, when clicking the right mouse button, an OnMouseDown event is not fired until the mouse is released. It gets worse when clicking several buttons at once: pressing the left mouse button, the right mouse button, releasing the left mouse button and finally the right one, causes two OnMouseDown events to be fired - one for each button, along with *3* OnMouseUp events, *all* for the right mouse button.

To fix this, I've put together my own tree view control, inherited from TTreeView, which contains OnMouseButtonDown and OnMouseButtonUp events, along with 6 procedures used to recieve windows messages:

[pascal]
procedure LMouseDown(var Msg: TMsg); message WM_LBUTTONDOWN;
procedure LMouseUp(var Msg: TMsg); message WM_LBUTTONUP;
procedure MMouseDown(var Msg: TMsg); message WM_MBUTTONDOWN;
procedure MMouseUp(var Msg: TMsg); message WM_MBUTTONUP;
procedure RMouseDown(var Msg: TMsg); message WM_RBUTTONDOWN;
procedure RMouseUp(var Msg: TMsg); message WM_RBUTTONUP;
[/pascal]

These procedures go on to fire the OnMouseButtonDown and OnMouseButtonUp events. This seems to fix the old behaviour, however, by doing this I seem to have destroyed the control's own mouse handling --- it no-longer reports regular OnMouseDown and OnMouseUp events, as well as not performing basic things such as selecting nodes when they are clicked on. I'm guessing the 6 procedures above used to handle window's messages are conflicting with other procedures used by one of the classes my control is derived from.

Ok, to the point: Is there anyway to keep my own handlers and events for the mouse, whilst allowing the control to function properly?

If it matters, I'm using Delphi 7 Personal Edition --- no VCL source code.