@@ -53,6 +53,7 @@ TDrawTreeForm = class(TForm)
5353 var InitialStates: TVirtualNodeInitStates);
5454 procedure TrackBar1Change (Sender: TObject);
5555 procedure VDT1StateChange (Sender: TBaseVirtualTree; Enter, Leave: TVirtualTreeStates);
56+ procedure FormDestroy (Sender: TObject);
5657 private
5758 FThumbSize: Integer;
5859 FExtensionsInitialized: Boolean;
@@ -189,6 +190,11 @@ procedure TDrawTreeForm.FormCreate(Sender: TObject);
189190 FThumbSize := 200 ;
190191end ;
191192
193+ procedure TDrawTreeForm.FormDestroy (Sender: TObject);
194+ begin
195+ FreeAndNil(FExtensionList);
196+ end ;
197+
192198// ----------------------------------------------------------------------------------------------------------------------
193199
194200function TDrawTreeForm.CanDisplay (const Name : string): Boolean;
@@ -334,58 +340,60 @@ procedure TDrawTreeForm.VDT1InitNode(Sender: TBaseVirtualTree; ParentNode, Node:
334340 end
335341 else
336342 begin
337- Picture := TPicture.Create;
338343 Data.Display := ExtractFileName(ExcludeTrailingBackslash(Data.FullPath));
339344 if (Data.Attributes and SFGAO_FOLDER) = 0 then
340- try
345+ begin
346+ Picture := TPicture.Create;
341347 try
342- Data.Image := TBitmap.Create;
343- Picture.LoadFromFile(Data.FullPath);
344- if not (Picture.Graphic is TBitmap) then
345- begin
346- // Some extra steps needed to keep non TBitmap descentants alive when
347- // scaling. This is needed because when accessing Picture.Bitmap all
348- // non-TBitmap content will simply be erased (definitly the wrong
349- // action, but we can't do anything to prevent this). Hence we
350- // must explicitly draw the graphic to a bitmap.
351- with Data.Image do
348+ try
349+ Data.Image := TBitmap.Create;
350+ Picture.LoadFromFile(Data.FullPath);
351+ if not (Picture.Graphic is TBitmap) then
352352 begin
353- Width := Picture.Width;
354- Height := Picture.Height;
355- Canvas.Draw(0 , 0 , Picture.Graphic);
353+ // Some extra steps needed to keep non TBitmap descentants alive when
354+ // scaling. This is needed because when accessing Picture.Bitmap all
355+ // non-TBitmap content will simply be erased (definitly the wrong
356+ // action, but we can't do anything to prevent this). Hence we
357+ // must explicitly draw the graphic to a bitmap.
358+ with Data.Image do
359+ begin
360+ Width := Picture.Width;
361+ Height := Picture.Height;
362+ Canvas.Draw(0 , 0 , Picture.Graphic);
363+ end ;
364+ Picture.Bitmap.Assign(Data.Image);
356365 end ;
357- Picture.Bitmap.Assign(Data.Image);
358- end ;
359- RescaleImage(Picture.Bitmap, Data.Image);
360-
361- // Collect some additional image properties.
362- Data.Properties := Data.Properties + Format(' %d x %d pixels' , [Picture.Width, Picture.Height]);
363- case Picture.Bitmap.PixelFormat of
364- pf1bit:
365- Data.Properties := Data.Properties + ' , 2 colors' ;
366- pf4bit:
367- Data.Properties := Data.Properties + ' , 16 colors' ;
368- pf8bit:
369- Data.Properties := Data.Properties + ' , 256 colors' ;
370- pf15bit:
371- Data.Properties := Data.Properties + ' , 32K colors' ;
372- pf16bit:
373- Data.Properties := Data.Properties + ' , 64K colors' ;
374- pf24bit:
375- Data.Properties := Data.Properties + ' , 16M colors' ;
376- pf32bit:
377- Data.Properties := Data.Properties + ' , 16M+ colors' ;
366+ RescaleImage(Picture.Bitmap, Data.Image);
367+
368+ // Collect some additional image properties.
369+ Data.Properties := Data.Properties + Format(' %d x %d pixels' , [Picture.Width, Picture.Height]);
370+ case Picture.Bitmap.PixelFormat of
371+ pf1bit:
372+ Data.Properties := Data.Properties + ' , 2 colors' ;
373+ pf4bit:
374+ Data.Properties := Data.Properties + ' , 16 colors' ;
375+ pf8bit:
376+ Data.Properties := Data.Properties + ' , 256 colors' ;
377+ pf15bit:
378+ Data.Properties := Data.Properties + ' , 32K colors' ;
379+ pf16bit:
380+ Data.Properties := Data.Properties + ' , 64K colors' ;
381+ pf24bit:
382+ Data.Properties := Data.Properties + ' , 16M colors' ;
383+ pf32bit:
384+ Data.Properties := Data.Properties + ' , 16M+ colors' ;
385+ end ;
386+ if Cardinal(Data.Image.Height) + 4 > TVirtualDrawTree(Sender).DefaultNodeHeight then
387+ Sender.NodeHeight[Node] := Data.Image.Height + 4 ;
388+ except
389+ Data.Image.Free;
390+ Data.Image := nil ;
378391 end ;
379- if Cardinal(Data.Image.Height) + 4 > TVirtualDrawTree(Sender).DefaultNodeHeight then
380- Sender.NodeHeight[Node] := Data.Image.Height + 4 ;
381- except
382- Data.Image.Free;
383- Data.Image := nil ;
384- end ;
385- finally
386- Picture.Free;
387- end ;
388- end ;
392+ finally
393+ Picture.Free;
394+ end ;// try..finally
395+ end ;// if
396+ end ;// else
389397 Data.Attributes := ReadAttributes(Data.FullPath);
390398 if ((Data.Attributes and SFGAO_HASSUBFOLDER) <> 0 ) or
391399 (((Data.Attributes and SFGAO_FOLDER) <> 0 ) and HasChildren(Data.FullPath)) then
0 commit comments