delphi - TStringGrid - OnMouseUp is not called! -


I have a strange behavior with TStringGrid in Delphi 7. Delphi does not call on-menuup event if a pop-up menu is connected, basically on the grid, when RMB is pressed, it cancels the menu pop somehow / delays the on-mouseup. To be 100% accurate, next time you press a mouse button, the on-mouse up is called twice - once for the current event, and once for a lost / delayed event.

This will suppress the whole logic, as the unwanted code, the program will be called next time when the user will press the mouse button.

Automatic popping is the answer to the right mouse button on a context menu. OnMouseUp events are also requested from the same click, before the pop-up is shown, VCL developers can choose either 'on-mouseup' event or later. Apparently there is an impact, i.e., when the popup is closed, the event is removed (either by the mouse or by pressing 'esk').

There is no doubling of this incident, when you press the left button to close the popup, by releasing the left button you are running the 'OnMouseUp' event again.


You have several options to get a new class and override the MouseDown method to fire your own event. An example;

  Type TMyStringGrid = Class (TStringGrid) Private FOnRButtonUp: TMouseEvent; Safe Process MouseDown (Button: TMouse Button; Shift: TIFFSTATE; X, Y: Integer); Override; Published property onb button: TMouseEvent FOnRButtonUp to FOnRButtonUp; End; [...] Process TStringGrid.MouseDown (Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Then start (button = MBRITE) and assigned (FOnRBttonup) then FOnBbuttonup (Self, Button, Shift, X, Y); inherited from; End;  


Another option may be to handle VM_RBUTTONUP messages, either to get a new class as above or to the grid's WindowProc . In this there is an example of changing WindowPros.


The only option is to drop the mouse-up event and you can process your code in the OnPopup event. This event has been removed before the popup is shown. You can get the mouse coordinates with Mouse.CursorPos .


However, an optional option can be used to set the AutoPopup property of the popup menu incorrect , and OnMouseUp In the event (or OnContextMenu event is far better) first do some processing and then show popups. An example;

  Process TForm1.StringGrid1MouseUp (Sender: Tubewite; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Var patt: T-point; Start // if the button = MBRITE then start, then protein: = (sender in the form of treading grid). Clienttoscreen (Point (X, Y)); PopupMenu1.Popup (Pt.X, Pt.Y); End; End;  

Comments