Skip to content

Commit e38734e

Browse files
committed
First chnage for #832: Turn TVirtualNode.Parent into a readonly property.
1 parent 73d9a15 commit e38734e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Source/VirtualTrees.BaseTree.pas

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4328,7 +4328,7 @@ procedure TBaseVirtualTree.InitRootNode(OldSize: Cardinal = 0);
43284328
// Indication that this node is the root node.
43294329
PrevSibling := FRoot;
43304330
NextSibling := FRoot;
4331-
Parent := Pointer(Self);
4331+
SetParent(Pointer(Self));
43324332
States := [vsInitialized, vsExpanded, vsHasChildren, vsVisible];
43334333
TotalHeight := FDefaultNodeHeight;
43344334
TotalCount := 1;
@@ -5049,7 +5049,7 @@ procedure TBaseVirtualTree.SetChildCount(Node: PVirtualNode; NewChildCount: Card
50495049
Child.PrevSibling := Node.LastChild;
50505050
if Assigned(Node.LastChild) then
50515051
Node.LastChild.NextSibling := Child;
5052-
Child.Parent := Node;
5052+
Child.SetParent(Node);
50535053
Node.LastChild := Child;
50545054
if Node.FirstChild = nil then
50555055
Node.FirstChild := Child;
@@ -13775,7 +13775,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1377513775
Node.PrevSibling := Destination.PrevSibling;
1377613776
Destination.PrevSibling := Node;
1377713777
Node.NextSibling := Destination;
13778-
Node.Parent := Destination.Parent;
13778+
Node.SetParent(Destination.Parent);
1377913779
Node.Index := Destination.Index;
1378013780
if Node.PrevSibling = nil then
1378113781
Node.Parent.FirstChild := Node
@@ -13795,7 +13795,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1379513795
Node.NextSibling := Destination.NextSibling;
1379613796
Destination.NextSibling := Node;
1379713797
Node.PrevSibling := Destination;
13798-
Node.Parent := Destination.Parent;
13798+
Node.SetParent(Destination.Parent);
1379913799
if Node.NextSibling = nil then
1380013800
Node.Parent.LastChild := Node
1380113801
else
@@ -13827,7 +13827,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1382713827
Node.NextSibling := nil;
1382813828
end;
1382913829
Node.PrevSibling := nil;
13830-
Node.Parent := Destination;
13830+
Node.SetParent(Destination);
1383113831
Node.Index := 0;
1383213832
// reindex all following nodes
1383313833
Run := Node.NextSibling;
@@ -13854,7 +13854,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1385413854
Node.PrevSibling := nil;
1385513855
end;
1385613856
Node.NextSibling := nil;
13857-
Node.Parent := Destination;
13857+
Node.SetParent(Destination);
1385813858
if Assigned(Node.PrevSibling) then
1385913859
Node.Index := Node.PrevSibling.Index + 1
1386013860
else
@@ -15137,7 +15137,7 @@ function TBaseVirtualTree.ReadChunk(Stream: TStream; Version: Integer; Node: PVi
1513715137
else
1513815138
Node.FirstChild := Run;
1513915139
Node.LastChild := Run;
15140-
Run.Parent := Node;
15140+
Run.SetParent(Node);
1514115141

1514215142
ReadNode(Stream, Version, Run);
1514315143
System.Dec(ChunkBody.ChildCount);

Source/VirtualTrees.Types.pas

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,11 +893,15 @@ TScrollBarOptions = class(TPersistent)
893893
// Note: Some copy routines require that all pointers (as well as the data area) in a node are
894894
// located at the end of the node! Hence if you want to add new member fields (except pointers to internal
895895
// data) then put them before field Parent.
896-
Parent, // reference to the node's parent (for the root this contains the treeview)
896+
private
897+
fParent: PVirtualNode; // link to the node's last child...
898+
public // reference to the node's parent (for the root this contains the treeview)
897899
PrevSibling, // link to the node's previous sibling or nil if it is the first node
898900
NextSibling, // link to the node's next sibling or nil if it is the last node
899901
FirstChild, // link to the node's first child...
900902
LastChild: PVirtualNode; // link to the node's last child...
903+
procedure SetParent(const pParent: PVirtualNode); inline; //internal method, do not call directly but use Parent[Node] := x on tree control.
904+
property Parent: PVirtualNode read fParent;
901905
private
902906
Data: record end; // this is a placeholder, each node gets extra data determined by NodeDataSize
903907
public
@@ -1165,6 +1169,11 @@ procedure TVirtualNode.SetData<T>(pUserData: T);
11651169
Include(Self.States, vsOnFreeNodeCallRequired);
11661170
end;
11671171

1172+
procedure TVirtualNode.SetParent(const pParent: PVirtualNode);
1173+
begin
1174+
fParent := pParent;
1175+
end;
1176+
11681177
//----------------------------------------------------------------------------------------------------------------------
11691178

11701179

0 commit comments

Comments
 (0)