[SOLVED] 'Competing' Event Handling lazarus / 31-LCL ---------------------------------------------------------------------- MountainQ · 2018-08-23 15:56 Hi everyone, I have a list of files represented in a TStringGrid. Based on shift state on the onmousedown event, the files get plotted in different windows. In addition, the selection can also change by other means (keyboard or mousewheel). These events are handled by calling the onmousedown event. My question is: what is the correct way of ignoring the onselection event that follows the onmousedown event? Just storing a boolean variable is possible, but I have the impression there is a more elegant way. Is it for example possible to delete the upcoming onselection event? Thanks. ---------------------------------------------------------------------- lucamar · 2018-08-23 16:33 Quote from: MountainQ on August 23, 2018, 05:56:44 pmJust storing a boolean variable is possible, but I have the impression there is a more elegant way. Is it for example possible to delete the upcoming onselection event? Short of subclassing the control---and even then, if internally---I don't think you can do that without using a centinel var. After all, it's not so inelegant Or you could reestructure your code to call independent "stateful" procs/functions from the event handlers. It's a tiny bit more complex and, definitely, "elegant".  ---- edit: to rephrase ---------------------------------------------------------------------- howardpc · 2018-08-23 16:35 One way is to have a private OnSelection field in the form which holds a reference to the 'live' event. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...private    FSelectionHandler: TOnSelectEvent;  ... Then code your grid mouseDown and mouseUp events something like this, setting the grid's OnSelection event to Nil during the period the any mouse button is down: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.gridMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var  g: TStringGrid absolute Sender;begin  if Sender is TStringGrid then    begin      FSelectionHandler := g.OnSelection;      g.OnSelection := Nil;       // your code here    end;end; procedure TForm1.gridMouseUp(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var  g: TStringGrid absolute Sender;begin  if Sender is TStringGrid then    begin      // your code here       g.OnSelection := FSelectionHandler;    end;end; ---------------------------------------------------------------------- MountainQ · 2018-08-24 07:18 Thanks to both of you for the rapid reply. Both answers contain the idea that I have to manually store the state, whether directly (sentinel) or indirectly (keep a a reference of the onselection method). And that's what I did: - OnMouseDown stores the state - OnGridSelection performs the task depending on the state (and also resets it) The only thing that would make it more compact is to have the shift state available the the OnGridSelection event. But also without it, I am rather happy with the solution. Thank you one more time.