type file://查询线程定义 TMultiQuery = class(TThread) private ADOQry :TADOQuery; fDatasource :TDataSource; { Private declarations } protected procedure Execute; override; procedure ConnectDataSource; public constructor create(qry :TADOQuery;datasource :TDataSource);virtual; end;
var
t1,t2,t3,t4 :TMultiQuery;
procedure TForm1.btnThreadClick(Sender: TObject); begin t1 :=TMultiQuery.create(adoquery1,datasource1); t2 :=TMultiQuery.create(adoquery2,datasource2); t3 :=TMultiQuery.create(adoquery3,datasource3); t4 :=TMultiQuery.create(adoquery4,datasource4
end;
constructor TMultiQuery.create(qry :TADOQuery;datasource :TDataSource); begin ADOQry :=qry; fDataSource :=datasource; inherited create(true); file://挂起线程 freeonterminate :=false; end;
procedure TMultiQuery.ConnectDataSource; begin FDataSource.DataSet := ADOQry; file://vcl是非安全线程代码,执行完后要再次连接dataset_____ end;
procedure TMultiQuery.Execute; begin ADOQry.Open; Synchronize(ConnectDataSource); end;
procedure TForm1.btnStartStopClick(Sender: TObject); begin if t1.Suspended then t1.Resume; if t2.Suspended then t2.Resume; if t3.Suspended then t3.Resume; if t4.Suspended then t4.Resume; end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin t4.Terminate; t4.Destroy; t3.Terminate; t3.Destroy; t2.Terminate; t2.Destroy; t1.Terminate; t1.Destroy; end;