Unintentional tStringGrid.OnFixedCellClick shooting behind tOpenDialog

I am using Delphi Berlin on Windows 10. I need to use tOpenDialog for tForm on tStringGrid.

When you double-click a file that overlaps a fixed column or row in an open dialog box, the FixedCellClick event fires automatically immediately after the open dialog disappears. In the following image, the file is in the same position as the fixed line, which is the first line.

enter image description here

type TForm1 = class(TForm) StringGrid1: TStringGrid; OpenDialog1: TOpenDialog; procedure FormClick(Sender: TObject); procedure StringGrid1FixedCellClick(Sender: TObject; ACol, ARow: Integer); procedure FormCreate(Sender: TObject); end; procedure TForm1.FormCreate(Sender: TObject); begin StringGrid1.Options := StringGrid1.Options + [goFixedColClick, goFixedRowClick]; end; procedure TForm1.FormClick(Sender: TObject); begin OpenDialog1.Execute; end; procedure TForm1.StringGrid1FixedCellClick(Sender: TObject; ACol, ARow: Integer); begin Caption := ''; end; 

In most cases, I can handle this by moving the dialog box or clicking the file once and clicking the Open button, but I cannot guarantee that other people who will use it will do this.

What is the reason and how can I solve this problem?

+5
source share
1 answer

I believe this is a problem in how TCustomGrid fires its OnFixedCellClick event in a mouse message (in the overriden MouseUp method) without checking if there was a corresponding mouse message ( FHotTrackCell.Pressed ). Quick fix (if you can copy and modify Vcl.Grids ): on line 4564 in Berlin (in TCustomGrid.MouseUp method add one more condition for verification, which will result in FixedCellClick calling):

 if ... and FHotTrackCell.Pressed then FixedCellClick(Cell.X, Cell.Y); 

In other words, do not call FixedCellClick if the mouse moves without the previous corresponding mouse click.

+5
source

All Articles