LCL/ShellListView: Fix accessing unallocated handle in PopulateWithRoot/GetBuiltInImageIndex, issue #39860.

This commit is contained in:
wp_xyz 2022-08-15 13:46:55 +02:00
parent 2f2a344de2
commit 4fba69291d

View File

@ -214,6 +214,7 @@ type
FMask: string;
FMaskCaseSensitivity: TMaskCaseSensitivity;
FObjectTypes: TObjectTypes;
FPopulateDelayed: Boolean;
FRoot: string;
FShellTreeView: TCustomShellTreeView;
FUseBuiltInIcons: Boolean;
@ -228,6 +229,7 @@ type
{ Methods specific to Lazarus }
class procedure WSRegisterClass; override;
procedure AdjustColWidths;
procedure CreateHandle; override;
procedure PopulateWithRoot();
procedure DoOnResize; override;
procedure SetAutoSizeColumns(const Value: Boolean); virtual;
@ -1529,6 +1531,13 @@ begin
// Check inputs
if Trim(FRoot) = '' then Exit;
// Check handle
if not HandleAllocated then
begin
FPopulateDelayed := true;
Exit;
end;
Items.BeginUpdate;
Files := TStringList.Create;
try
@ -1607,6 +1616,16 @@ begin
end;
end;
procedure TCustomShellListView.CreateHandle;
begin
inherited;
if FPopulateDelayed then
begin
PopulateWithRoot;
FPopulateDelayed := false;
end;
end;
procedure TCustomShellListView.DoOnResize;
begin
inherited;