TListBoxなどのVCLコントロールでBeginUpdateとEndUpdateを使用すると、EndUpdateが呼び出されるまでコントロールが再描画されないように、Itemsでコントロールを読み込む処理が高速化されることがわかります。TStringListにBeginUpdateとEndUpdateがあるのはなぜですか?
例:
procedure TForm1.AddItems;
var
i: Integer;
begin
Screen.Cursor := crHourGlass;
try
ListBox1.Items.BeginUpdate;
try
for i := 0 to 5000 do
begin
ListBox1.Items.Add('Item' + IntToStr(i));
end;
finally
ListBox1.Items.EndUpdate;
end;
finally
Screen.Cursor := crDefault;
end;
end;
:
procedure TForm1.AddItems;
var
i: Integer;
begin
Screen.Cursor := crHourGlass;
try
for i := 0 to 5000 do
begin
ListBox1.Items.Add('Item' + IntToStr(i));
end;
finally
Screen.Cursor := crDefault;
end;
end;
リストボックスを再描画することが許可されているが、遅延はそうよう再描画防止することによって短絡させることができるため、上記の遅延を有することになります
今私はTStringListを使ってこれをテストしました:
procedure TForm1.AddItems;
var
SL: TStringList;
i: Integer;
begin
SL := TStringList.Create;
try
Screen.Cursor := crHourGlass;
try
SL.BeginUpdate;
try
for i := 0 to 5000 do
begin
SL.Add('Item' + IntToStr(i));
end;
finally
SL.EndUpdate;
end;
ListBox1.Items.Assign(SL);
finally
Screen.Cursor := crDefault;
end;
finally
SL.Free;
end;
end;
TStringListのはメモリ内で実行していない視覚れるよう
が、彼らは本当にかかわらず、必要とされて... TStringListのはBegindUpdateとEndUpdateのを使用していますかどうかに関係なく、リストはほぼ同じ速度で移入されているようです。とにかく、TStringListでBeginUpdateとEndUpdateを使用する必要があります。これを行うのは良い方法ですか?
私はこれを聞いて馬鹿げているのですが、なぜTStringListにBeginUpdateとEndUpdateという手順がありますか?
あなたの意見を聞きたいと思っています。
感謝:)
+1また、OnChangeイベントを禁止します。 – RRUZ
@RRUZ、確かに!ヒントをありがとう。 –
ありがとう@UweRaabe私は知らないでしょう –