我以前实现的一个方法: 在一个pageControl上有40个tabsheet,每一个上都有各种控件,每次打开该tabsheet则自动将控件连到该datasource上。咦,我好像是答非所问。 for i:=0 to ComponentCount-1 do begin if Components[i] is TDBcomboBox then with Components[i] as TDBcomboBox do begin dataSource:= DataSource2; //指向一个空的DataSource2,相当于清空。不清空会出故障。 if Tag = pageNo+1 then DataSource := needDataSource; end; if Components[i] is TDBedit then with Components[i] as TDBedit do begin dataSource:=DataSource2; if Tag = pageNo+1 then DataSource := needDataSource; end; if Components[i] is TDBmemo then with Components[i] as TDBmemo do begin dataSource:=DataSource2; if Tag = pageNo+1 then DataSource := needDataSource; end; if Components[i] is TDBcheckBox then with Components[i] as TDBcheckBox do begin dataSource:=DataSource2; if Tag = pageNo+1 then DataSource := needDataSource; end; if Components[i] is TDBImage then with Components[i] as TDBImage do begin dataSource:=DataSource2; if Tag = pageNo+1 then DataSource := needDataSource; end; end;
当然,我认为如能在静态时没好就一个表一个datasource
不然,要动态的换Dataset,可能会产生抖动
在一个pageControl上有40个tabsheet,每一个上都有各种控件,每次打开该tabsheet则自动将控件连到该datasource上。咦,我好像是答非所问。
for i:=0 to ComponentCount-1 do
begin
if Components[i] is TDBcomboBox then
with Components[i] as TDBcomboBox do
begin
dataSource:= DataSource2; //指向一个空的DataSource2,相当于清空。不清空会出故障。
if Tag = pageNo+1 then
DataSource := needDataSource;
end;
if Components[i] is TDBedit then
with Components[i] as TDBedit do
begin
dataSource:=DataSource2;
if Tag = pageNo+1 then
DataSource := needDataSource;
end;
if Components[i] is TDBmemo then
with Components[i] as TDBmemo do
begin
dataSource:=DataSource2;
if Tag = pageNo+1 then
DataSource := needDataSource;
end;
if Components[i] is TDBcheckBox then
with Components[i] as TDBcheckBox do
begin
dataSource:=DataSource2;
if Tag = pageNo+1 then
DataSource := needDataSource;
end;
if Components[i] is TDBImage then
with Components[i] as TDBImage do
begin
dataSource:=DataSource2;
if Tag = pageNo+1 then
DataSource := needDataSource;
end;
end;