From ce366f425cca5d0ecd3a20db17b796a3876e364b Mon Sep 17 00:00:00 2001 From: wp Date: Sun, 4 Nov 2018 11:20:15 +0000 Subject: [PATCH] VirtualTreeView: Fix occasional crash when imagelists are nil. git-svn-id: trunk@59444 - --- components/virtualtreeview/VirtualTrees.pas | 87 +++++++++++++-------- 1 file changed, 55 insertions(+), 32 deletions(-) diff --git a/components/virtualtreeview/VirtualTrees.pas b/components/virtualtreeview/VirtualTrees.pas index 322ad76fc1..2abac66547 100644 --- a/components/virtualtreeview/VirtualTrees.pas +++ b/components/virtualtreeview/VirtualTrees.pas @@ -9475,8 +9475,13 @@ var ColImageInfo.Index := GetCheckImage(nil, FCheckType, FCheckState, IsEnabled); ColImageInfo.XPos := GlyphPos.X; ColImageInfo.YPos := GlyphPos.Y; - w := ColImageInfo.Images.Width; - h := ColImageInfo.Images.Height; + if ColImageInfo.Images <> nil then begin + w := ColImageInfo.Images.Width; + h := ColImageInfo.Images.Height; + end else begin + w := 0; + h := 0; + end; PaintCheckImage(TargetCanvas, ColImageInfo, False); end; end; @@ -22073,66 +22078,84 @@ end; function TBaseVirtualTree.GetRealImagesWidth: Integer; begin - {$IF LCL_FullVersion >= 2000000} - Result := FImages.ResolutionForPPI[FImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Width; - {$ELSE} - Result := FImages.Width; - {$IFEND} + if FImages = nil then + Result := 0 + else + {$IF LCL_FullVersion >= 2000000} + Result := FImages.ResolutionForPPI[FImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Width; + {$ELSE} + Result := FImages.Width; + {$IFEND} end; //---------------------------------------------------------------------------------------------------------------------- function TBaseVirtualTree.GetRealImagesHeight: Integer; begin - {$IF LCL_FullVersion >= 2000000} - Result := FImages.ResolutionForPPI[FImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Height; - {$ELSE} - Result := FImages.Height; - {$IFEND} + if FImages = nil then + Result := 0 + else + {$IF LCL_FullVersion >= 2000000} + Result := FImages.ResolutionForPPI[FImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Height; + {$ELSE} + Result := FImages.Height; + {$IFEND} end; //---------------------------------------------------------------------------------------------------------------------- function TBaseVirtualTree.GetRealStateImagesWidth: Integer; begin - {$IF LCL_FullVersion >= 2000000} - Result := FStateImages.ResolutionForPPI[FStateImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Width; - {$ELSE} - Result := FStateImages.Width; - {$IFEND} + if FStateImages = nil then + Result := 0 + else + {$IF LCL_FullVersion >= 2000000} + Result := FStateImages.ResolutionForPPI[FStateImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Width; + {$ELSE} + Result := FStateImages.Width; + {$IFEND} end; //---------------------------------------------------------------------------------------------------------------------- function TBaseVirtualTree.GetRealStateImagesHeight: Integer; begin - {$IF LCL_FullVersion >= 2000000} - Result := FStateImages.ResolutionForPPI[FStateImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Height; - {$ELSE} - Result := FStateImages.Height; - {$IFEND} + if FStateImages = nil then + Result := 0 + else + {$IF LCL_FullVersion >= 2000000} + Result := FStateImages.ResolutionForPPI[FStateImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Height; + {$ELSE} + Result := FStateImages.Height; + {$IFEND} end; //---------------------------------------------------------------------------------------------------------------------- function TBaseVirtualTree.GetRealCheckImagesWidth: Integer; begin - {$IF LCL_FullVersion >= 2000000} - Result := FCheckImages.ResolutionForPPI[FCheckImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Width; - {$ELSE} - Result := FCheckImages.Width; - {$IFEND} + if FCheckImages = nil then + Result := 0 + else + {$IF LCL_FullVersion >= 2000000} + Result := FCheckImages.ResolutionForPPI[FCheckImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Width; + {$ELSE} + Result := FCheckImages.Width; + {$IFEND} end; //---------------------------------------------------------------------------------------------------------------------- function TBaseVirtualTree.GetRealCheckImagesHeight: Integer; begin - {$IF LCL_FullVersion >= 2000000} - Result := FCheckImages.ResolutionForPPI[FCheckImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Height; - {$ELSE} - Result := FCheckImages.Height; - {$IFEND} + if FCheckImages = nil then + Result := 0 + else + {$IF LCL_FullVersion >= 2000000} + Result := FCheckImages.ResolutionForPPI[FCheckImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Height; + {$ELSE} + Result := FCheckImages.Height; + {$IFEND} end; //----------------------------------------------------------------------------------------------------------------------