使用TTHread同时打开更多ClientDataSet

时间:2018-09-06 18:51:50

标签: delphi tclientdataset tthread

我是一个在delphi中有线程的初学者。我写了这段代码,效果很好。

首先打开ClientDataSet1直到完成,然后再打开ClientDataSet2,依此类推。

我的问题是:如何开始同时打开它们。

TTHread.CreateAnonymousThread(
procedure
begin
  TTHread.Synchronize(nil,
    procedure
    begin
      with ClientDataSet1 do
        try
          ProgressBar1.Max := 2000; // number of records of ClientDataSet1
          PacketRecords := 50;
          Open;
          DisableControls;
          while not Eof do
          begin
            ProgressBar1.Position := ProgressBar1.Position + 1;
            Label1.Caption := ClientDataSet1.RecordCount.ToString;
            Next;
            Application.ProcessMessages;
          end;
          EnableControls;
        except
          // ShowMessage(Msg);
        end;
    end);

  TTHread.Synchronize(nil,
    procedure
    begin
      with ClientDataSet2 do
        try
          ProgressBar2.Max := 2330; // number of records of ClientDataSet2
          PacketRecords := 80;
          Open;
          DisableControls;
          while not Eof do
          begin
            ProgressBar2.Position := ProgressBar2.Position + 1;
            Label2.Caption := ClientDataSet2.RecordCount.ToString;
            Next;
            Application.ProcessMessages;
          end;
          EnableControls;
        except
          // ShowMessage(Msg);
        end;
    end);
end).Start;

请帮助我。

0 个答案:

没有答案