...
...
...
procedure DBGrid1CellClick(Column: TColumn);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
procedure ActiveControlChanged(Sender: TObject);
procedure ShowStatus(DataSource: TObject; Field: string);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
TypInfo;
{$R *.dfm}
procedure TForm1.ActiveControlChanged(Sender: TObject);
var
Obj: TObject;
Field: string;
begin
Obj := nil;
Field := '';
if Screen.ActiveControl <> nil then
begin
if GetPropInfo(Screen.ActiveControl, 'DataSource', [tkClass]) <> nil then
Obj := GetObjectProp(Screen.ActiveControl, 'DataSource', TDataSource);
if GetPropInfo(Screen.ActiveControl, 'DataField', [tkString, tkLString]) <> nil then
Field := GetStrProp(Screen.ActiveControl, 'DataField');
end;
ShowStatus(Obj, Field);
end;
procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
ShowStatus(Column.Grid.DataSource, Column.FieldName);
end;
procedure TForm1.ShowStatus(DataSource: TObject; Field: string);
begin
if (DataSource is TDataSource) and
(TDataSource(DataSource).DataSet is TADOQuery) then
StatusBar1.Panels[0].Text := '当前Query:' + TDataSource(DataSource).DataSet.Name
else
StatusBar1.Panels[0].Text := '';
if Field <> '' then
StatusBar1.Panels[1].Text := '当前字段:' + Field
else
StatusBar1.Panels[1].Text := '';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Screen.OnActiveControlChange := ActiveControlChanged;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Screen.OnActiveControlChange := nil;
end;
...
...
...
TDBGrid就用OnCellClick事件,其它标准数据感知控件就用Screen.OnActiveControlChange
用TApplication.OnIdle事件应该也可以