VirtualTreeView: Fix memory leaks in Advanced demo

This commit is contained in:
wp_xyz 2024-10-04 19:56:21 +02:00
parent 96b5fe52c4
commit 3c2da22f52
15 changed files with 131 additions and 37 deletions

View File

@ -8,9 +8,9 @@ object AlignForm: TAlignForm
ClientHeight = 470
ClientWidth = 768
Constraints.MinWidth = 590
LCLVersion = '3.99.0.0'
OnCreate = FormCreate
OnDestroy = FormDestroy
LCLVersion = '2.1.0.0'
object Label8: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
@ -185,6 +185,7 @@ object AlignForm: TAlignForm
TreeOptions.PaintOptions = [toHideFocusRect, toShowButtons, toShowDropmark, toShowRoot, toShowTreeLines, toThemeAware]
TreeOptions.SelectionOptions = [toExtendedFocus, toMultiSelect]
OnFocusChanged = AlignTreeFocusChanged
OnFreeNode = AlignTreeFreeNode
OnGetText = AlignTreeGetText
OnPaintText = AlignTreePaintText
OnGetImageIndex = AlignTreeGetImageIndex
@ -210,9 +211,9 @@ object AlignForm: TAlignForm
'Right'
'Center'
)
OnChange = AlignComboChange
Style = csDropDownList
TabOrder = 1
OnChange = AlignComboChange
end
object AlignCombo1: TComboBox
Tag = 1
@ -229,9 +230,9 @@ object AlignForm: TAlignForm
'Right'
'Center'
)
OnChange = AlignComboChange
Style = csDropDownList
TabOrder = 2
OnChange = AlignComboChange
end
object AlignCombo2: TComboBox
Tag = 2
@ -250,9 +251,9 @@ object AlignForm: TAlignForm
'Right'
'Center'
)
OnChange = AlignComboChange
Style = csDropDownList
TabOrder = 3
OnChange = AlignComboChange
end
object BidiGroup0: TRadioGroup
AnchorSideLeft.Control = AlignCombo0
@ -283,8 +284,8 @@ object AlignForm: TAlignForm
'left-to-right'
'right-to-left'
)
OnClick = BidiGroupClick
TabOrder = 4
OnClick = BidiGroupClick
end
object BidiGroup1: TRadioGroup
Tag = 1
@ -314,8 +315,8 @@ object AlignForm: TAlignForm
'left-to-right'
'right-to-left'
)
OnClick = BidiGroupClick
TabOrder = 5
OnClick = BidiGroupClick
end
object BidiGroup2: TRadioGroup
Tag = 2
@ -347,8 +348,8 @@ object AlignForm: TAlignForm
'left-to-right'
'right-to-left'
)
OnClick = BidiGroupClick
TabOrder = 6
OnClick = BidiGroupClick
end
object GroupBox1: TGroupBox
AnchorSideLeft.Control = Owner
@ -370,50 +371,50 @@ object AlignForm: TAlignForm
Left = 0
Height = 19
Top = 0
Width = 87
Width = 85
Caption = 'Show glyphs'
OnClick = OptionBoxClick
TabOrder = 0
OnClick = OptionBoxClick
end
object HotTrackOptionBox: TCheckBox
Tag = 1
Left = 0
Height = 19
Top = 21
Width = 69
Width = 67
Caption = 'Hot track'
OnClick = OptionBoxClick
TabOrder = 1
OnClick = OptionBoxClick
end
object ShowTextOptionBox: TCheckBox
Tag = 2
Left = 0
Height = 19
Top = 42
Width = 72
Width = 70
Caption = 'Show text'
OnClick = OptionBoxClick
TabOrder = 2
OnClick = OptionBoxClick
end
object VisibleOptionBox: TCheckBox
Tag = 3
Left = 0
Height = 19
Top = 63
Width = 54
Width = 52
Caption = 'Visible'
OnClick = OptionBoxClick
TabOrder = 3
OnClick = OptionBoxClick
end
object EnabledOptionBox: TCheckBox
Tag = 4
Left = 0
Height = 19
Top = 84
Width = 62
Width = 60
Caption = 'Enabled'
OnClick = OptionBoxClick
TabOrder = 4
OnClick = OptionBoxClick
end
end
object LayoutCombo: TComboBox
@ -434,9 +435,9 @@ object AlignForm: TAlignForm
'Glyph top'
'Glyph bottom'
)
OnChange = LayoutComboChange
Style = csDropDownList
TabOrder = 8
OnChange = LayoutComboChange
end
object TreeImages: TImageList
Left = 544

View File

@ -41,6 +41,7 @@ type
EnabledOptionBox: TCheckBox;
Label5: TLabel;
LayoutCombo: TComboBox;
procedure AlignTreeFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure AlignTreeGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var Index: Integer);
procedure AlignTreeGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
@ -201,6 +202,17 @@ begin
end;
end;
procedure TAlignForm.AlignTreeFreeNode(Sender: TBaseVirtualTree; Node:
PVirtualNode);
var
Data: PAlignData;
begin
Data := Sender.GetNodeData(Node);
Data.MainColumnText := '';
Data.GreekText := '';
Data.RTLText := '';
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAlignForm.AlignTreeInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;

View File

@ -123,6 +123,7 @@ object GeneralForm: TGeneralForm
TreeOptions.StringOptions = [toSaveCaptions, toShowStaticText, toAutoAcceptEditChange]
OnDragOver = VST2DragOver
OnFocusChanging = VST2FocusChanging
OnFreeNode = VST2FreeNode
OnGetText = VST2GetText
OnPaintText = VST2PaintText
OnGetImageIndexEx = VST2GetImageIndexEx

View File

@ -49,6 +49,7 @@ type
ImageList1: TImageList;
procedure TreeFontButtonClick(Sender: TObject);
procedure ButtonFillModeComboChange(Sender: TObject);
procedure VST2FreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure VST2InitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;
var InitialStates: TVirtualNodeInitStates);
procedure VST2InitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode; var ChildCount: Cardinal);
@ -357,6 +358,8 @@ begin
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TGeneralForm.ButtonFillModeComboChange(Sender: TObject);
begin
VST2.ButtonFillMode := TVTButtonFillMode(ButtonFillModeCombo.ItemIndex);
@ -364,6 +367,19 @@ end;
//----------------------------------------------------------------------------------------------------------------------
procedure TGeneralForm.VST2FreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode
);
var
Data: PNodeData2;
begin
Data := Sender.GetNodeData(Node);
Data^.Caption := '';
Data^.StaticText := '';
Data^.ForeignText := '';
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TGeneralForm.CheckMarkComboChange(Sender: TObject);
begin

View File

@ -126,6 +126,7 @@ object GridForm: TGridForm
OnBeforeItemErase = VST5BeforeItemErase
OnCreateEditor = VST5CreateEditor
OnFocusChanging = VST5FocusChanging
OnFreeNode = VST5FreeNode
OnGetText = VST5GetText
OnPaintText = VST5PaintText
OnInitNode = VST5InitNode

View File

@ -34,6 +34,7 @@ type
procedure VST5CreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink);
procedure VST5FocusChanging(Sender: TBaseVirtualTree; OldNode, NewNode: PVirtualNode; OldColumn,
NewColumn: TColumnIndex; var Allowed: Boolean);
procedure VST5FreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure VST5GetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: String);
procedure VST5InitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;
@ -96,6 +97,16 @@ begin
Allowed := NewColumn > 0;
end;
procedure TGridForm.VST5FreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
var
Data: PGridData;
begin
Data := Sender.GetNodeData(Node);
Data.Value[0] := '';
Data.Value[1] := '';
Data.Value[2] := '';
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TGridForm.VST5InitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;

View File

@ -7,8 +7,8 @@ object PropertiesForm: TPropertiesForm
Caption = 'PropertiesForm'
ClientHeight = 389
ClientWidth = 637
LCLVersion = '3.99.0.0'
OnCreate = FormCreate
LCLVersion = '2.1.0.0'
object Label9: TLabel
AnchorSideLeft.Control = VST3
AnchorSideLeft.Side = asrBottom
@ -91,6 +91,7 @@ object PropertiesForm: TPropertiesForm
OnChange = VST3Change
OnCreateEditor = VST3CreateEditor
OnEditing = VST3Editing
OnFreeNode = VST3FreeNode
OnGetText = VST3GetText
OnPaintText = VST3PaintText
OnGetImageIndex = VST3GetImageIndex
@ -129,8 +130,8 @@ object PropertiesForm: TPropertiesForm
'Forward'
'Backward'
)
OnClick = RadioGroup1Click
TabOrder = 1
OnClick = RadioGroup1Click
end
object TreeImages: TImageList
Left = 504

View File

@ -28,6 +28,7 @@ type
procedure VST3Change(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure VST3CreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink);
procedure VST3Editing(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; var Allowed: Boolean);
procedure VST3FreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure VST3GetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
var LineBreakStyle: TVTTooltipLineBreakStyle; var HintText: String);
procedure VST3GetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
@ -187,6 +188,17 @@ end;
//----------------------------------------------------------------------------------------------------------------------
procedure TPropertiesForm.VST3FreeNode(Sender: TBaseVirtualTree;
Node: PVirtualNode);
var
data: PPropertyData;
begin
data := Sender.GetNodeData(Node);
data^.Value := '';
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TPropertiesForm.VST3Change(Sender: TBaseVirtualTree; Node: PVirtualNode);
begin

View File

@ -7,10 +7,10 @@ object VisibilityForm: TVisibilityForm
Caption = 'VisibilityForm'
ClientHeight = 536
ClientWidth = 969
LCLVersion = '3.99.0.0'
OnCreate = FormCreate
OnHide = FormHide
OnShow = FormShow
LCLVersion = '2.1.0.0'
object Label17: TLabel
AnchorSideLeft.Control = VST1
AnchorSideLeft.Side = asrBottom
@ -103,7 +103,7 @@ object VisibilityForm: TVisibilityForm
Left = 528
Height = 108
Top = 87
Width = 192
Width = 190
AutoFill = True
AutoSize = True
BorderSpacing.Top = 16
@ -117,7 +117,7 @@ object VisibilityForm: TVisibilityForm
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 88
ClientWidth = 188
ClientWidth = 186
ItemIndex = 0
Items.Strings = (
'show all nodes'
@ -125,8 +125,8 @@ object VisibilityForm: TVisibilityForm
'hide nodes with children only'
'hide all nodes'
)
OnClick = RadioGroup1Click
TabOrder = 2
OnClick = RadioGroup1Click
end
object Panel2: TPanel
AnchorSideLeft.Control = Owner
@ -4201,6 +4201,7 @@ object VisibilityForm: TVisibilityForm
OnChange = VST2Change
OnCollapsed = VSTCollapsedExpanded
OnExpanded = VSTCollapsedExpanded
OnFreeNode = VST2FreeNode
OnGetText = VST2GetText
OnInitChildren = VST2InitChildren
OnInitNode = VST1InitNode
@ -8272,6 +8273,7 @@ object VisibilityForm: TVisibilityForm
OnChange = VST2Change
OnCollapsed = VSTCollapsedExpanded
OnExpanded = VSTCollapsedExpanded
OnFreeNode = VST3FreeNode
OnGetText = VST2GetText
OnInitChildren = VST2InitChildren
OnInitNode = VST1InitNode

View File

@ -33,8 +33,10 @@ type
var InitialStates: TVirtualNodeInitStates);
procedure FormCreate(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure VST2FreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure VST2GetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: String);
procedure VST3FreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure VST3Scroll(Sender: TBaseVirtualTree; DeltaX, DeltaY: Integer);
procedure VST2InitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode; var ChildCount: Cardinal);
procedure VST2Scroll(Sender: TBaseVirtualTree; DeltaX, DeltaY: Integer);
@ -166,6 +168,15 @@ begin
end;
end;
procedure TVisibilityForm.VST2FreeNode(Sender: TBaseVirtualTree; Node:
PVirtualNode);
var
Data: PLinkData;
begin
Data := Sender.GetNodeData(Node);
Data^.Caption := '';
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVisibilityForm.VST2GetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
@ -182,6 +193,15 @@ begin
CellText := Data.Caption;
end;
procedure TVisibilityForm.VST3FreeNode(Sender: TBaseVirtualTree; Node:
PVirtualNode);
var
Data: PLinkData;
begin
Data := Sender.GetNodeData(Node);
Data^.Caption := '';
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVisibilityForm.VST3Scroll(Sender: TBaseVirtualTree; DeltaX, DeltaY: Integer);

View File

@ -8,8 +8,8 @@ object WindowsXPForm: TWindowsXPForm
ClientHeight = 449
ClientWidth = 844
Font.CharSet = ANSI_CHARSET
LCLVersion = '3.99.0.0'
OnCreate = FormCreate
LCLVersion = '2.3.0.0'
object Label1: TLabel
AnchorSideLeft.Control = XPTree
AnchorSideLeft.Side = asrBottom
@ -17,7 +17,7 @@ object WindowsXPForm: TWindowsXPForm
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 567
Height = 147
Height = 75
Top = 34
Width = 273
Anchors = [akTop, akLeft, akRight]
@ -33,8 +33,8 @@ object WindowsXPForm: TWindowsXPForm
AnchorSideRight.Control = Label1
AnchorSideRight.Side = asrBottom
Left = 567
Height = 147
Top = 213
Height = 75
Top = 141
Width = 273
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 32
@ -49,8 +49,8 @@ object WindowsXPForm: TWindowsXPForm
AnchorSideRight.Side = asrBottom
Cursor = crHandPoint
Left = 567
Height = 168
Top = 392
Height = 90
Top = 248
Width = 273
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 32
@ -129,6 +129,7 @@ object WindowsXPForm: TWindowsXPForm
TreeOptions.PaintOptions = [toHideFocusRect, toShowButtons, toShowDropmark, toShowRoot]
TreeOptions.SelectionOptions = [toMultiSelect]
OnCompareNodes = XPTreeCompareNodes
OnFreeNode = XPTreeFreeNode
OnGetText = XPTreeGetText
OnGetImageIndex = XPTreeGetImageIndex
OnGetHint = XPTreeGetHint
@ -156,41 +157,41 @@ object WindowsXPForm: TWindowsXPForm
Style = tbsDropDown
end
object ToolButton10: TToolButton
Left = 47
Left = 50
Top = 2
ImageIndex = 10
Style = tbsDropDown
end
object ToolButton11: TToolButton
Left = 93
Left = 99
Top = 2
ImageIndex = 18
end
object ToolButton12: TToolButton
Left = 127
Left = 136
Top = 2
ImageIndex = 14
end
object ToolButton13: TToolButton
Left = 161
Left = 173
Top = 2
ImageIndex = 21
end
object ToolButton14: TToolButton
Left = 195
Left = 210
Top = 2
ImageIndex = 8
Style = tbsDropDown
end
object ToolButton15: TToolButton
Left = 241
Left = 259
Height = 32
Top = 2
Caption = 'ToolButton15'
Style = tbsSeparator
end
object ToolButton16: TToolButton
Left = 249
Left = 267
Top = 2
Caption = 'Click here to print the treeview.'
ImageIndex = 24

View File

@ -34,6 +34,7 @@ type
Label2: TLabel;
Label4: TLabel;
PrintDialog: TPrintDialog;
procedure XPTreeFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure XPTreeGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind;
Column: TColumnIndex; var Ghosted: Boolean; var Index: Integer);
procedure FormCreate(Sender: TObject);
@ -118,6 +119,15 @@ begin
end;
end;
procedure TWindowsXPForm.XPTreeFreeNode(Sender: TBaseVirtualTree; Node:
PVirtualNode);
var
Data: PEntry;
begin
Data := Sender.GetNodeData(Node);
Data.Caption := '';
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TWindowsXPForm.FormCreate(Sender: TObject);

View File

@ -9,6 +9,7 @@
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
</General>

View File

@ -14,6 +14,8 @@ uses
{$R *.res}
begin
Application.Scaled := True;
Application.Title := '';
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;

View File

@ -62,6 +62,9 @@
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>