虽然以下代码确实使用鼠标所在单元格的文本正确设置了 Form1.Caption,但除非我单击单元格,否则它不会显示任何 DBGrid.Hint 。
这张照片有什么问题?
type
THackGrid = class(TDBGrid); // to expose protected DataLink property
procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
Cell: TGridCoord;
ActRec: Integer;
begin
Cell := DBGrid1.MouseCoord(X, Y);
if dgIndicator in DBGrid1.Options then
Dec(Cell.X);
if dgTitles in DBGrid1.Options then
Dec(Cell.Y);
if THackGrid(DBGrid1).DataLink.Active and (Cell.X >= 0) and
(Cell.Y >= 0) then
begin
ActRec := THackGrid(DBGrid1).DataLink.ActiveRecord;
try
THackGrid(DBGrid1).DataLink.ActiveRecord := Cell.Y;
Caption := DBGrid1.Columns[Cell.X].Field.AsString; // Form1.Caption shows fine!
DBGrid.Hint := DBGrid1.Columns[Cell.X].Field.AsString; // <== Hint only shows when I click into the cell!
finally
THackGrid(DBGrid1).DataLink.ActiveRecord := ActRec;
end;
end;
end;