Skip to content

Commit 07fa2dd

Browse files
committed
Change for #832: Turn TVirtualNode.LastChild into a readonly property…
1 parent b4cd92f commit 07fa2dd

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

Source/VirtualTrees.BaseTree.pas

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5047,9 +5047,9 @@ procedure TBaseVirtualTree.SetChildCount(Node: PVirtualNode; NewChildCount: Card
50475047
if Assigned(Node.LastChild) then
50485048
Node.LastChild.SetNextSibling(Child);
50495049
Child.SetParent(Node);
5050-
Node.LastChild := Child;
5050+
Node.SetLastChild(Child);
50515051
if Node.FirstChild = nil then
5052-
Node.FirstChild := Child;
5052+
Node.SetFirstChild(Child);
50535053
System.Dec(Remaining);
50545054
System.Inc(Index);
50555055

@@ -13775,7 +13775,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1377513775
Node.SetParent(Destination.Parent);
1377613776
Node.SetIndex(Destination.Index);
1377713777
if Node.PrevSibling = nil then
13778-
Node.Parent.FirstChild := Node
13778+
Node.Parent.SetFirstChild(Node)
1377913779
else
1378013780
Node.PrevSibling.SetNextSibling(Node);
1378113781

@@ -13794,7 +13794,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1379413794
Node.SetPrevSibling(Destination);
1379513795
Node.SetParent(Destination.Parent);
1379613796
if Node.NextSibling = nil then
13797-
Node.Parent.LastChild := Node
13797+
Node.Parent.SetLastChild(Node)
1379813798
else
1379913799
Node.NextSibling.SetPrevSibling(Node);
1380013800
Node.SetIndex(Destination.Index);
@@ -13814,13 +13814,13 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1381413814
// If there's a first child then there must also be a last child.
1381513815
Destination.FirstChild.SetPrevSibling(Node);
1381613816
Node.SetNextSibling(Destination.FirstChild);
13817-
Destination.FirstChild := Node;
13817+
Destination.SetFirstChild(Node);
1381813818
end
1381913819
else
1382013820
begin
1382113821
// First child node at this location.
13822-
Destination.FirstChild := Node;
13823-
Destination.LastChild := Node;
13822+
Destination.SetFirstChild(Node);
13823+
Destination.SetLastChild(Node);
1382413824
Node.SetNextSibling(nil);
1382513825
end;
1382613826
Node.SetPrevSibling(nil);
@@ -13841,13 +13841,13 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1384113841
// If there's a last child then there must also be a first child.
1384213842
Destination.LastChild.SetNextSibling(Node);
1384313843
Node.SetPrevSibling(Destination.LastChild);
13844-
Destination.LastChild := Node;
13844+
Destination.SetLastChild(Node);
1384513845
end
1384613846
else
1384713847
begin
1384813848
// first child node at this location
13849-
Destination.FirstChild := Node;
13850-
Destination.LastChild := Node;
13849+
Destination.SetFirstChild(Node);
13850+
Destination.SetLastChild(Node);
1385113851
Node.SetPrevSibling(nil);
1385213852
end;
1385313853
Node.SetNextSibling(nil);
@@ -13957,7 +13957,7 @@ procedure TBaseVirtualTree.InternalDisconnectNode(Node: PVirtualNode; KeepFocus:
1395713957
if Assigned(Node.PrevSibling) then
1395813958
Node.PrevSibling.SetNextSibling(Node.NextSibling)
1395913959
else
13960-
Parent.FirstChild := Node.NextSibling;
13960+
Parent.SetFirstChild(Node.NextSibling);
1396113961

1396213962
if Assigned(Node.NextSibling) then
1396313963
begin
@@ -13976,7 +13976,7 @@ procedure TBaseVirtualTree.InternalDisconnectNode(Node: PVirtualNode; KeepFocus:
1397613976
end;
1397713977
end
1397813978
else
13979-
Parent.LastChild := Node.PrevSibling;
13979+
Parent.SetLastChild(Node.PrevSibling);
1398013980
end;
1398113981
end;
1398213982

@@ -15132,8 +15132,8 @@ function TBaseVirtualTree.ReadChunk(Stream: TStream; Version: Integer; Node: PVi
1513215132
if Assigned(Node.LastChild) then
1513315133
Node.LastChild.SetNextSibling(Run)
1513415134
else
15135-
Node.FirstChild := Run;
15136-
Node.LastChild := Run;
15135+
Node.SetFirstChild(Run);
15136+
Node.SetLastChild(Run);
1513715137
Run.SetParent(Node);
1513815138

1513915139
ReadNode(Stream, Version, Run);
@@ -16912,8 +16912,8 @@ procedure TBaseVirtualTree.DeleteChildren(Node: PVirtualNode; ResetHasChildren:
1691216912
AdjustTotalHeight(Node, NodeHeight[Node]);
1691316913
AdjustTotalCount(Node, 1);
1691416914
end;
16915-
Node.FirstChild := nil;
16916-
Node.LastChild := nil;
16915+
Node.SetFirstChild(nil);
16916+
Node.SetLastChild(nil);
1691716917
finally
1691816918
System.Dec(FUpdateCount);
1691916919
end;
@@ -22463,9 +22463,9 @@ procedure TBaseVirtualTree.Sort(Node: PVirtualNode; Column: TColumnIndex; Direct
2246322463
try
2246422464
// Sort the linked list, check direction flag only once.
2246522465
if Direction = sdAscending then
22466-
Node.FirstChild := MergeSortAscending(Node.FirstChild, Node.ChildCount)
22466+
Node.SetFirstChild(MergeSortAscending(Node.FirstChild, Node.ChildCount))
2246722467
else
22468-
Node.FirstChild := MergeSortDescending(Node.FirstChild, Node.ChildCount);
22468+
Node.SetFirstChild(MergeSortDescending(Node.FirstChild, Node.ChildCount));
2246922469
finally
2247022470
EndOperation(okSortNode);
2247122471
end;
@@ -22481,7 +22481,7 @@ procedure TBaseVirtualTree.Sort(Node: PVirtualNode; Column: TColumnIndex; Direct
2248122481
Run.NextSibling.SetPrevSibling(Run);
2248222482
Run := Run.NextSibling;
2248322483
until False;
22484-
Node.LastChild := Run;
22484+
Node.SetLastChild(Run);
2248522485

2248622486
InvalidateCache;
2248722487
end;

Source/VirtualTrees.Types.pas

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,18 +904,23 @@ TScrollBarOptions = class(TPersistent)
904904
private
905905
fParent: PVirtualNode; // reference to the node's parent (for the root this contains the treeview)
906906
fPrevSibling: PVirtualNode; // link to the node's previous sibling or nil if it is the first node
907-
fNextSibling: PVirtualNode; // link to the node's next sibling or nil if it is the last node
907+
fNextSibling: PVirtualNode; // link to the node's next sibling or nil if it is the last node
908+
public // still public as it is used as var parameter in MergeSortAscending()
909+
FirstChild: PVirtualNode; // link to the node's first child...
910+
private
911+
fLastChild: PVirtualNode; // link to the node's last child...
908912
public
909-
FirstChild, // link to the node's first child...
910-
LastChild: PVirtualNode; // link to the node's last child...
911913
procedure SetParent(const pParent: PVirtualNode); inline; //internal method, do not call directly but use Parent[Node] := x on tree control.
912914
procedure SetPrevSibling(const pPrevSibling: PVirtualNode); inline; //internal method, do not call directly
913915
procedure SetNextSibling(const pNextSibling: PVirtualNode); inline; //internal method, do not call directly
916+
procedure SetFirstChild(const pFirstChild: PVirtualNode); inline; //internal method, do not call directly
917+
procedure SetLastChild(const pLastChild: PVirtualNode); inline; //internal method, do not call directly
914918
procedure SetIndex(const pIndex: Cardinal); inline; //internal method, do not call directly.
915919
property Index: Cardinal read fIndex;
916920
property Parent: PVirtualNode read fParent;
917921
property PrevSibling: PVirtualNode read fPrevSibling;
918922
property NextSibling: PVirtualNode read fNextSibling;
923+
property LastChild: PVirtualNode read fLastChild;
919924
private
920925
Data: record end; // this is a placeholder, each node gets extra data determined by NodeDataSize
921926
public
@@ -1182,6 +1187,16 @@ procedure TVirtualNode.SetData<T>(pUserData: T);
11821187
Include(Self.States, vsOnFreeNodeCallRequired);
11831188
end;
11841189

1190+
procedure TVirtualNode.SetFirstChild(const pFirstChild: PVirtualNode);
1191+
begin
1192+
FirstChild := pFirstChild;
1193+
end;
1194+
1195+
procedure TVirtualNode.SetLastChild(const pLastChild: PVirtualNode);
1196+
begin
1197+
fLastChild := pLastChild;
1198+
end;
1199+
11851200
procedure TVirtualNode.SetIndex(const pIndex: Cardinal);
11861201
begin
11871202
fIndex := pIndex;

0 commit comments

Comments
 (0)