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