Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unintended tStringGrid.OnFixedCellClick firing behind tOpenDialog

I use Delphi Berlin on Windows 10. I need to use tOpenDialog on a tStringGrid based tForm.

When I double click a file which overlaps a fixed column or row on an open dialog onFixedCellClick event fires automatically right after the disapperance of the open dialog. In the following image the file is on the same position of fixed row 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 window or clicking the file once and clicking open button but I can't guarantee that other people who will use this would do that.

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

like image 370
JO SeongGng Avatar asked Sep 02 '16 12:09

JO SeongGng


1 Answers

I believe this is a problem in how TCustomGrid triggers its OnFixedCellClick event on a mouse-up message (in its overriden MouseUp method) without checking if there was a corresponding mouse-down message (FHotTrackCell.Pressed). A quick fix (if you can copy and modify Vcl.Grids): on line 4564 in Berlin (in TCustomGrid.MouseUp method add another condition to check, leading to the call to FixedCellClick):

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

In other words, don't call FixedCellClick if a mouse-up comes without a prior corresponding mouse-down.

like image 140
Ondrej Kelle Avatar answered Oct 27 '22 18:10

Ondrej Kelle