我在
Windows 10上使用Delphi Berlin.我需要在基于tStringGrid的tForm上使用tOpenDialog.
当我双击一个与打开的对话框上的固定列或行重叠的文件onFixedCellClick事件在打开对话框消失后立即自动触发.在下图中,文件位于第一行的固定行的相同位置.
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;
在大多数情况下,我可以通过移动对话框窗口或单击文件一次并单击打开按钮来处理此问题,但我无法保证将使用此功能的其他人会这样做.
是什么原因以及如何解决这个问题?
解决方法
我相信这是TCustomGrid如何在鼠标注释消息(在其重写的MouseUp方法中)触发其OnFixedCellClick事件而不检查是否存在相应的鼠标按下消息(FHottrackCell.pressed)的问题.快速修复(如果你可以复制和修改Vcl.Grids):在柏林的4564行(在TCustomGrid.MouseUp方法中添加另一个要检查的条件,导致调用FixedCellClick):
if ... and FHottrackCell.pressed then FixedCellClick(Cell.X,Cell.Y);
换句话说,如果没有先前相应的鼠标按下鼠标,则不要调用FixedCellClick.