delphi - tOpenDialog 后面意外触发 tStringGrid.OnFixedCellClick

标签 delphi tstringgrid topendialog

我在 Windows 10 上使用 Delphi Berlin。我需要在基于 tStringGrid 的 tForm 上使用 tOpenDialog。

当我双击与打开的对话框上的固定列或行重叠的文件时,onFixedCellClick 事件会在打开的对话框消失后立即自动触发。在下图中,文件位于固定行的同一位置,即第一行。

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;

在大多数情况下,我可以通过移动对话框窗口或单击文件一次并单击打开按钮来处理此问题,但我不能保证其他使用此功能的人会这样做。

这个问题是什么原因以及如何解决?

最佳答案

我认为这是 TCustomGrid 如何在鼠标释放消息上触发其 OnFixedCellClick 事件(在其重写的 MouseUp 方法中)的问题而不检查是否有相应的鼠标按下消息(FHotTrackCell.Pressed)。快速修复(如果您可以复制和修改Vcl.Grids):在柏林的第4564行(在TCustomGrid.MouseUp方法中添加另一个要检查的条件,导致调用到固定单元格点击):

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

换句话说,如果鼠标松开之前没有相应的鼠标按下,则不要调用 FixedCellClick

关于delphi - tOpenDialog 后面意外触发 tStringGrid.OnFixedCellClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39291978/

相关文章:

delphi - 当水平滚动条移动时 StringGrid 实时更新?

image - Delphi StringGrid 背景图片

delphi - 从 Delphi 中的 OpenDialog 选择中获取特殊文件夹路径

delphi - 如何确定接口(interface)的实现对象的类型

delphi - TStringGrid - 有没有一种简单的方法来获取 "current/selected"行?

delphi - 如何使用系统路径之外的dll

delphi - 有没有办法在 delphi 中禁用 TOpenDialog 的提示?

delphi - CopyMemory 导致 Win8 上的访问冲突

delphi - TFrame 作为组件,IDE 在第一次使用时将对象更改为内联