ShellCtrls: Speed up population of TShellListView by adding BeginUpdate/EndUpdate calls.

git-svn-id: trunk@64553 -
This commit is contained in:
wp 2021-02-12 15:04:54 +00:00
parent ad98b8ef31
commit b729025142

View File

@ -862,6 +862,7 @@ begin
if (csDesigning in ComponentState) then Exit; if (csDesigning in ComponentState) then Exit;
Files := TStringList.Create; Files := TStringList.Create;
Items.BeginUpdate;
try try
Files.OwnsObjects := True; Files.OwnsObjects := True;
GetFilesInDir(ANodePath, AllFilesMask, FObjectTypes, Files, FFileSortType); GetFilesInDir(ANodePath, AllFilesMask, FObjectTypes, Files, FFileSortType);
@ -886,6 +887,7 @@ begin
end; end;
finally finally
Files.Free; Files.Free;
Items.EndUpdate;
end; end;
end; end;
@ -899,11 +901,13 @@ var
begin begin
// avoids crashes in the IDE by not populating during design // avoids crashes in the IDE by not populating during design
if (csDesigning in ComponentState) then Exit; if (csDesigning in ComponentState) then Exit;
Items.BeginUpdate;
try
Items.Clear; Items.Clear;
r := GetLogicalDriveStrings(SizeOf(Drives), Drives); r := GetLogicalDriveStrings(SizeOf(Drives), Drives);
if r = 0 then Exit; if r = 0 then Exit;
if r > SizeOf(Drives) then Exit; if r > SizeOf(Drives) then Exit;
// raise Exception.Create(SysErrorMessage(ERROR_OUTOFMEMORY)); // raise Exception.Create(SysErrorMessage(ERROR_OUTOFMEMORY));
pDrive := Drives; pDrive := Drives;
while pDrive^ <> #0 do while pDrive^ <> #0 do
begin begin
@ -916,6 +920,9 @@ begin
NewNode.HasChildren := True; NewNode.HasChildren := True;
Inc(pDrive, 4); Inc(pDrive, 4);
end; end;
finally
Items.EndUpdate;
end;
end; end;
{$else} {$else}
var var
@ -1409,9 +1416,14 @@ begin
and not DirectoryExistsUtf8(ExpandFilenameUtf8(Value)) then and not DirectoryExistsUtf8(ExpandFilenameUtf8(Value)) then
Raise EInvalidPath.CreateFmt(sShellCtrlsInvalidRoot,[Value]); Raise EInvalidPath.CreateFmt(sShellCtrlsInvalidRoot,[Value]);
FRoot := Value; FRoot := Value;
BeginUpdate;
try
Clear; Clear;
Items.Clear; Items.Clear;
PopulateWithRoot(); PopulateWithRoot();
finally
EndUpdate;
end;
end; end;
end; end;
@ -1455,6 +1467,7 @@ begin
// Check inputs // Check inputs
if Trim(FRoot) = '' then Exit; if Trim(FRoot) = '' then Exit;
Items.BeginUpdate;
Files := TStringList.Create; Files := TStringList.Create;
try try
Files.OwnsObjects := True; Files.OwnsObjects := True;
@ -1489,6 +1502,7 @@ begin
Sort; Sort;
finally finally
Files.Free; Files.Free;
Items.EndUpdate;
end; end;
end; end;