将数百万条记录加载到字符串列表中可能会非常慢

Kam*_*igi 5 delphi tstringlist tadotable

我如何能够非常快速地将数百万条记录从tadotable加载到stringlist中?

procedure TForm1.SlowLoadingIntoStringList(StringList: TStringList);
begin
  StringList.Clear;
  with SourceTable do
  begin
    Open;
    DisableControls;
    try
      while not EOF do
    begin
      StringList.Add(FieldByName('OriginalData').AsString);
      Next;
    end;
   finally
   EnableControls;
   Close;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

Rav*_*123 10

在你的循环中你得到了这个领域.从循环中搜索该字段

procedure TForm1.SlowLoadingIntoStringList(StringList: TStringList); 
var
  oField: TField;
begin
  StringList.Clear;   
  with SourceTable do   
  begin     
    Open;     
    DisableControls;     
    try       
      oField:= FieldByName('OriginalData');
      if oField<>Nil then
      begin
        while not EOF do
        begin       
          StringList.Add(oField.AsString);       
          Next;     
        end;   
      end; 
    finally    
      EnableControls;    
      Close;   
    end; 
  end;  
end;
Run Code Online (Sandbox Code Playgroud)


Pol*_*ial 4

不幸的是,您无法快速完成此操作。这是一个本质上很慢的操作,需要大量的 CPU 时间和内存带宽来实现。你可以投入更多的硬件,但我怀疑你应该重新考虑你的任务。