Skip to content

Commit 5f08e00

Browse files
committed
Change for #832: Turn TVirtualNode.NextSibling into a readonly property.
1 parent db238f6 commit 5f08e00

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

Source/VirtualTrees.BaseTree.pas

+23-23
Original file line numberDiff line numberDiff line change
@@ -4325,7 +4325,7 @@ procedure TBaseVirtualTree.InitRootNode(OldSize: Cardinal = 0);
43254325
begin
43264326
// Indication that this node is the root node.
43274327
SetPrevSibling(FRoot);
4328-
NextSibling := FRoot;
4328+
SetNextSibling(FRoot);
43294329
SetParent(Pointer(Self));
43304330
States := [vsInitialized, vsExpanded, vsHasChildren, vsVisible];
43314331
TotalHeight := FDefaultNodeHeight;
@@ -5046,7 +5046,7 @@ procedure TBaseVirtualTree.SetChildCount(Node: PVirtualNode; NewChildCount: Card
50465046
Child.SetIndex(Index);
50475047
Child.SetPrevSibling(Node.LastChild);
50485048
if Assigned(Node.LastChild) then
5049-
Node.LastChild.NextSibling := Child;
5049+
Node.LastChild.SetNextSibling(Child);
50505050
Child.SetParent(Node);
50515051
Node.LastChild := Child;
50525052
if Node.FirstChild = nil then
@@ -13779,13 +13779,13 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1377913779
begin
1378013780
Node.SetPrevSibling(Destination.PrevSibling);
1378113781
Destination.SetPrevSibling(Node);
13782-
Node.NextSibling := Destination;
13782+
Node.SetNextSibling(Destination);
1378313783
Node.SetParent(Destination.Parent);
1378413784
Node.SetIndex(Destination.Index);
1378513785
if Node.PrevSibling = nil then
1378613786
Node.Parent.FirstChild := Node
1378713787
else
13788-
Node.PrevSibling.NextSibling := Node;
13788+
Node.PrevSibling.SetNextSibling(Node);
1378913789

1379013790
// reindex all following nodes
1379113791
Run := Destination;
@@ -13797,8 +13797,8 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1379713797
end;
1379813798
amInsertAfter:
1379913799
begin
13800-
Node.NextSibling := Destination.NextSibling;
13801-
Destination.NextSibling := Node;
13800+
Node.SetNextSibling(Destination.NextSibling);
13801+
Destination.SetNextSibling(Node);
1380213802
Node.SetPrevSibling(Destination);
1380313803
Node.SetParent(Destination.Parent);
1380413804
if Node.NextSibling = nil then
@@ -13821,15 +13821,15 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1382113821
begin
1382213822
// If there's a first child then there must also be a last child.
1382313823
Destination.FirstChild.SetPrevSibling(Node);
13824-
Node.NextSibling := Destination.FirstChild;
13824+
Node.SetNextSibling(Destination.FirstChild);
1382513825
Destination.FirstChild := Node;
1382613826
end
1382713827
else
1382813828
begin
1382913829
// First child node at this location.
1383013830
Destination.FirstChild := Node;
1383113831
Destination.LastChild := Node;
13832-
Node.NextSibling := nil;
13832+
Node.SetNextSibling(nil);
1383313833
end;
1383413834
Node.SetPrevSibling(nil);
1383513835
Node.SetParent(Destination);
@@ -13847,7 +13847,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1384713847
if Assigned(Destination.LastChild) then
1384813848
begin
1384913849
// If there's a last child then there must also be a first child.
13850-
Destination.LastChild.NextSibling := Node;
13850+
Destination.LastChild.SetNextSibling(Node);
1385113851
Node.SetPrevSibling(Destination.LastChild);
1385213852
Destination.LastChild := Node;
1385313853
end
@@ -13858,7 +13858,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1385813858
Destination.LastChild := Node;
1385913859
Node.SetPrevSibling(nil);
1386013860
end;
13861-
Node.NextSibling := nil;
13861+
Node.SetNextSibling(nil);
1386213862
Node.SetParent(Destination);
1386313863
if Assigned(Node.PrevSibling) then
1386413864
Node.SetIndex(Node.PrevSibling.Index + 1)
@@ -13963,7 +13963,7 @@ procedure TBaseVirtualTree.InternalDisconnectNode(Node: PVirtualNode; KeepFocus:
1396313963
System.Dec(FVisibleCount, CountVisibleChildren(Node) + Cardinal(IfThen(IsEffectivelyVisible[Node], 1)));
1396413964

1396513965
if Assigned(Node.PrevSibling) then
13966-
Node.PrevSibling.NextSibling := Node.NextSibling
13966+
Node.PrevSibling.SetNextSibling(Node.NextSibling)
1396713967
else
1396813968
Parent.FirstChild := Node.NextSibling;
1396913969

@@ -15138,7 +15138,7 @@ function TBaseVirtualTree.ReadChunk(Stream: TStream; Version: Integer; Node: PVi
1513815138
if Assigned(Run.PrevSibling) then
1513915139
Run.SetIndex(Run.PrevSibling.Index + 1);
1514015140
if Assigned(Node.LastChild) then
15141-
Node.LastChild.NextSibling := Run
15141+
Node.LastChild.SetNextSibling(Run)
1514215142
else
1514315143
Node.FirstChild := Run;
1514415144
Node.LastChild := Run;
@@ -16902,7 +16902,7 @@ procedure TBaseVirtualTree.DeleteChildren(Node: PVirtualNode; ResetHasChildren:
1690216902
Run := Run.PrevSibling;
1690316903
// Important, to avoid exchange of invalid pointers while disconnecting the node.
1690416904
if Assigned(Run) then
16905-
Run.NextSibling := nil;
16905+
Run.SetNextSibling(nil);
1690616906
DeleteNode(Mark, False, True);
1690716907
end;
1690816908
if ResetHasChildren then
@@ -22327,23 +22327,23 @@ procedure TBaseVirtualTree.Sort(Node: PVirtualNode; Column: TColumnIndex; Direct
2232722327

2232822328
if CompareResult <= 0 then
2232922329
begin
22330-
Result.NextSibling := A;
22330+
Result.SetNextSibling(A);
2233122331
Result := A;
2233222332
A := A.NextSibling;
2233322333
end
2233422334
else
2233522335
begin
22336-
Result.NextSibling := B;
22336+
Result.SetNextSibling(B);
2233722337
Result := B;
2233822338
B := B.NextSibling;
2233922339
end;
2234022340
end;
2234122341

2234222342
// Just append the list which is not nil (or set end of result list to nil if both lists are nil).
2234322343
if Assigned(A) then
22344-
Result.NextSibling := A
22344+
Result.SetNextSibling(A)
2234522345
else
22346-
Result.NextSibling := B;
22346+
Result.SetNextSibling(B);
2234722347
// return start of the new merged list
2234822348
Result := Dummy.NextSibling;
2234922349
end;
@@ -22370,23 +22370,23 @@ procedure TBaseVirtualTree.Sort(Node: PVirtualNode; Column: TColumnIndex; Direct
2237022370

2237122371
if CompareResult >= 0 then
2237222372
begin
22373-
Result.NextSibling := A;
22373+
Result.SetNextSibling(A);
2237422374
Result := A;
2237522375
A := A.NextSibling;
2237622376
end
2237722377
else
2237822378
begin
22379-
Result.NextSibling := B;
22379+
Result.SetNextSibling(B);
2238022380
Result := B;
2238122381
B := B.NextSibling;
2238222382
end;
2238322383
end;
2238422384

2238522385
// Just append the list which is not nil (or set end of result list to nil if both lists are nil).
2238622386
if Assigned(A) then
22387-
Result.NextSibling := A
22387+
Result.SetNextSibling(A)
2238822388
else
22389-
Result.NextSibling := B;
22389+
Result.SetNextSibling(B);
2239022390
// Return start of the newly merged list.
2239122391
Result := Dummy.NextSibling;
2239222392
end;
@@ -22411,7 +22411,7 @@ procedure TBaseVirtualTree.Sort(Node: PVirtualNode; Column: TColumnIndex; Direct
2241122411
begin
2241222412
Result := Node;
2241322413
Node := Node.NextSibling;
22414-
Result.NextSibling := nil;
22414+
Result.SetNextSibling(nil);
2241522415
end;
2241622416
end;
2241722417

@@ -22435,7 +22435,7 @@ procedure TBaseVirtualTree.Sort(Node: PVirtualNode; Column: TColumnIndex; Direct
2243522435
begin
2243622436
Result := Node;
2243722437
Node := Node.NextSibling;
22438-
Result.NextSibling := nil;
22438+
Result.SetNextSibling(nil);
2243922439
end;
2244022440
end;
2244122441

Source/VirtualTrees.Types.pas

+10-3
Original file line numberDiff line numberDiff line change
@@ -902,18 +902,20 @@ TScrollBarOptions = class(TPersistent)
902902
// located at the end of the node! Hence if you want to add new member fields (except pointers to internal
903903
// data) then put them before field Parent.
904904
private
905-
fParent: PVirtualNode; // link to the node's last child...
905+
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-
public // reference to the node's parent (for the root this contains the treeview)
908-
NextSibling, // 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
909909
FirstChild, // link to the node's first child...
910910
LastChild: PVirtualNode; // link to the node's last child...
911911
procedure SetParent(const pParent: PVirtualNode); inline; //internal method, do not call directly but use Parent[Node] := x on tree control.
912912
procedure SetPrevSibling(const pPrevSibling: PVirtualNode); inline; //internal method, do not call directly
913+
procedure SetNextSibling(const pNextSibling: PVirtualNode); inline; //internal method, do not call directly
913914
procedure SetIndex(const pIndex: Cardinal); inline; //internal method, do not call directly.
914915
property Index: Cardinal read fIndex;
915916
property Parent: PVirtualNode read fParent;
916917
property PrevSibling: PVirtualNode read fPrevSibling;
918+
property NextSibling: PVirtualNode read fNextSibling;
917919
private
918920
Data: record end; // this is a placeholder, each node gets extra data determined by NodeDataSize
919921
public
@@ -1195,6 +1197,11 @@ procedure TVirtualNode.SetPrevSibling(const pPrevSibling: PVirtualNode);
11951197
fPrevSibling := pPrevSibling;
11961198
end;
11971199

1200+
procedure TVirtualNode.SetNextSibling(const pNextSibling: PVirtualNode);
1201+
begin
1202+
fNextSibling := pNextSibling;
1203+
end;
1204+
11981205
//----------------------------------------------------------------------------------------------------------------------
11991206

12001207

0 commit comments

Comments
 (0)