Как вариант:
| Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, DBTables, Grids, DBGrids;
type TForm1 = class(TForm) DBGrid1: TDBGrid; Table1: TTable; DataSource1: TDataSource; procedure DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure FormCreate(Sender: TObject); private { Private declarations } procedure AppShowHint(var HintStr: String; var CanShow: Boolean; var HintInfo: Controls.THintInfo); public Cell: TGridCoord; { Public declarations } end;
TDBGrid = class(DBGrids.TDBGrid) end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.AppShowHint(var HintStr: String; var CanShow: Boolean; var HintInfo: Controls.THintInfo); begin if HintInfo.HintControl = DBGrid1 then if DBGrid1.Hint <> '' then begin HintStr := DBGrid1.Hint; // HintInfo.HintPos := ... HintInfo.CursorRect := TDBGrid(DBGrid1).CellRect(Cell.X, Cell.Y); end; end;
procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var Text: String; DLink: TDataLink; OldActiveRec: Integer; begin DBGrid1.Hint := ''; Cell := DBGrid1.MouseCoord(X, Y); with Cell do if (X > 0) and (Y > 0) then begin DLink := TDBGrid(DBGrid1).DataLink; if Assigned(DLink) then begin OldActiveRec := DLink.ActiveRecord; try DLink.ActiveRecord := Y - 1; Text := DBGrid1.Columns[X - 1].Field.Text; finally DLink.ActiveRecord := OldActiveRec; end; DBGrid1.Hint := Text; end; end; end;
procedure TForm1.FormCreate(Sender: TObject); begin Application.OnShowHint := AppShowHint; Application.HintPause := 500; DBGrid1.ShowHint := True; end;
end.
|
|