procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin for i:=0 to Components.ComponentCount -1 do begin if Components[i] is TDBGrid then begin if TDBGrid(Components[i]).DataSource.DataSet:=YourDataSet then begin // do sth end; end; end; end;
顺起来是很简单
datasource1.dataset := adoquery1;
dbgrid1.datasource := datasource1;
反起来我想也可以实现的
反过来可以嘛?想想就知道——————————————————————————————万一那个父亲有两个儿子呢?哈哈~~~~~~;P
var i:integer;
begin
for i:=0 to Components.ComponentCount -1 do
begin
if Components[i] is TDBGrid then
begin
if TDBGrid(Components[i]).DataSource.DataSet:=YourDataSet then
begin
// do sth
end;
end;
end;
end;