Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi FMX TListBox速度慢,列表大_Delphi_Firemonkey_Tlistbox_Delphi 10.4 Sydney - Fatal编程技术网

Delphi FMX TListBox速度慢,列表大

Delphi FMX TListBox速度慢,列表大,delphi,firemonkey,tlistbox,delphi-10.4-sydney,Delphi,Firemonkey,Tlistbox,Delphi 10.4 Sydney,我正在将2000个名字加载到FMX TListBox中,这花费的时间太长(比如35秒或更长) 以下是测试代码: procedure TDocWindow.DEBUGAddLotsOfStringsToList; var theTimeAtStart: Integer; J: Integer; begin ListBox1.Clear; theTimeAtStart := TThread.GetTickCount; for J := 1 to 2200 do be

我正在将2000个名字加载到FMX TListBox中,这花费的时间太长(比如35秒或更长)

以下是测试代码:

procedure TDocWindow.DEBUGAddLotsOfStringsToList;
var
  theTimeAtStart: Integer;
  J: Integer;

begin
  ListBox1.Clear;

  theTimeAtStart := TThread.GetTickCount;

  for J := 1 to 2200 do
    begin
      ListBox1.Items.Add(j.toString);
    end;

  ShowMessage('There were ' + J.ToString + ' strings added to the list in ' + (TThread.GetTickCount - theTimeAtStart).ToString + ' milliseconds.');
end;

TListBox是否有什么东西使它对于几千个字符串来说太慢了?

使用
BeginUpdate
EndUpdate
将我的系统上的运行时间从25秒减少到大约125毫秒

procedure TForm1.Button1Click(Sender: TObject);
var
  theTimeAtStart: Integer;
  J: Integer;
begin
  theTimeAtStart := TThread.GetTickCount;

  ListBox1.Items.BeginUpdate;

  try
    ListBox1.Clear;

    for J := 1 to 2200 do
    begin
      ListBox1.Items.Add(j.ToString());
    end;
  finally
    ListBox1.Items.EndUpdate;
  end;
  ShowMessage('There were ' + J.ToString + ' strings added to the list in ' + (TThread.GetTickCount - theTimeAtStart).ToString + ' milliseconds.');
end;

Clear()
也应该在
(Begin | End)Update
对中。@RemyLebeau:已修复。谢谢。当我添加Begin/EndUpdate块时,我没有注意到这一点。@KenWhite:你为什么把
BeginUpdate
放在
try
之后?@AndreasRejbrand:出于同样的原因,我不小心把
Clear
放在
BeginUpdate
之前固定的。谢谢。