Skip to content

Commit 599d64d

Browse files
committed
Issue #1212: Fixed mem leaks
1 parent 684fd09 commit 599d64d

File tree

2 files changed

+66
-57
lines changed

2 files changed

+66
-57
lines changed

Demos/Advanced/DrawTreeDemo.dfm

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
object DrawTreeForm: TDrawTreeForm
22
Left = 544
33
Top = 320
4-
Width = 726
5-
Height = 513
4+
ClientHeight = 475
5+
ClientWidth = 714
66
Color = clBtnFace
77
Font.Charset = ANSI_CHARSET
88
Font.Color = clWindowText
99
Font.Height = -13
1010
Font.Name = 'Trebuchet MS'
1111
Font.Style = []
12-
OldCreateOrder = False
1312
OnCreate = FormCreate
13+
OnDestroy = FormDestroy
1414
DesignSize = (
15-
710
15+
714
1616
475)
17-
PixelsPerInch = 96
1817
TextHeight = 18
1918
object Label7: TLabel
2019
Left = 0
2120
Top = 0
22-
Width = 710
21+
Width = 714
2322
Height = 61
2423
Align = alTop
2524
AutoSize = False
@@ -32,15 +31,15 @@ object DrawTreeForm: TDrawTreeForm
3231
end
3332
object Label1: TLabel
3433
Left = 4
35-
Top = 381
34+
Top = 390
3635
Width = 247
3736
Height = 18
3837
Anchors = [akLeft, akBottom]
3938
Caption = 'Adjust vertical image alignment of nodes:'
4039
end
4140
object Label3: TLabel
4241
Left = 424
43-
Top = 381
42+
Top = 390
4443
Width = 22
4544
Height = 18
4645
Anchors = [akLeft, akBottom]
@@ -49,8 +48,8 @@ object DrawTreeForm: TDrawTreeForm
4948
object VDT1: TVirtualDrawTree
5049
Left = 10
5150
Top = 84
52-
Width = 684
53-
Height = 278
51+
Width = 690
52+
Height = 287
5453
Anchors = [akLeft, akTop, akRight, akBottom]
5554
AutoExpandDelay = 200
5655
AutoScrollDelay = 200
@@ -92,6 +91,8 @@ object DrawTreeForm: TDrawTreeForm
9291
OnInitChildren = VDT1InitChildren
9392
OnInitNode = VDT1InitNode
9493
OnStateChange = VDT1StateChange
94+
Touch.InteractiveGestures = [igPan, igPressAndTap]
95+
Touch.InteractiveGestureOptions = [igoPanSingleFingerHorizontal, igoPanSingleFingerVertical, igoPanInertia, igoPanGutter, igoParentPassthrough]
9596
Columns = <
9697
item
9798
BiDiMode = bdLeftToRight
@@ -113,7 +114,7 @@ object DrawTreeForm: TDrawTreeForm
113114
end
114115
object TrackBar1: TTrackBar
115116
Left = 264
116-
Top = 379
117+
Top = 388
117118
Width = 157
118119
Height = 21
119120
Anchors = [akLeft, akBottom]

Demos/Advanced/DrawTreeDemo.pas

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
190191
end;
191192

193+
procedure TDrawTreeForm.FormDestroy(Sender: TObject);
194+
begin
195+
FreeAndNil(FExtensionList);
196+
end;
197+
192198
//----------------------------------------------------------------------------------------------------------------------
193199

194200
function 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

Comments
 (0)