Skip to content

Commit dd066ed

Browse files
committed
Change for #832: Turn TVirtualNode.Index into a readonly property.
1 parent e38734e commit dd066ed

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

Source/VirtualTrees.BaseTree.pas

+12-12
Original file line numberDiff line numberDiff line change
@@ -5045,7 +5045,7 @@ procedure TBaseVirtualTree.SetChildCount(Node: PVirtualNode; NewChildCount: Card
50455045
while Remaining > 0 do
50465046
begin
50475047
Child := MakeNewNode;
5048-
Child.Index := Index;
5048+
Child.SetIndex(Index);
50495049
Child.PrevSibling := Node.LastChild;
50505050
if Assigned(Node.LastChild) then
50515051
Node.LastChild.NextSibling := Child;
@@ -13776,7 +13776,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1377613776
Destination.PrevSibling := Node;
1377713777
Node.NextSibling := Destination;
1377813778
Node.SetParent(Destination.Parent);
13779-
Node.Index := Destination.Index;
13779+
Node.SetIndex(Destination.Index);
1378013780
if Node.PrevSibling = nil then
1378113781
Node.Parent.FirstChild := Node
1378213782
else
@@ -13786,7 +13786,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1378613786
Run := Destination;
1378713787
while Assigned(Run) do
1378813788
begin
13789-
System.Inc(Run.Index);
13789+
Run.SetIndex(Run.Index + 1);
1379013790
Run := Run.NextSibling;
1379113791
end;
1379213792
end;
@@ -13800,13 +13800,13 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1380013800
Node.Parent.LastChild := Node
1380113801
else
1380213802
Node.NextSibling.PrevSibling := Node;
13803-
Node.Index := Destination.Index;
13803+
Node.SetIndex(Destination.Index);
1380413804

1380513805
// reindex all following nodes
1380613806
Run := Node;
1380713807
while Assigned(Run) do
1380813808
begin
13809-
System.Inc(Run.Index);
13809+
Run.SetIndex(Run.Index + 1);
1381013810
Run := Run.NextSibling;
1381113811
end;
1381213812
end;
@@ -13828,12 +13828,12 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1382813828
end;
1382913829
Node.PrevSibling := nil;
1383013830
Node.SetParent(Destination);
13831-
Node.Index := 0;
13831+
Node.SetIndex(0);
1383213832
// reindex all following nodes
1383313833
Run := Node.NextSibling;
1383413834
while Assigned(Run) do
1383513835
begin
13836-
System.Inc(Run.Index);
13836+
Run.SetIndex(Run.Index + 1);
1383713837
Run := Run.NextSibling;
1383813838
end;
1383913839
end;
@@ -13856,9 +13856,9 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1385613856
Node.NextSibling := nil;
1385713857
Node.SetParent(Destination);
1385813858
if Assigned(Node.PrevSibling) then
13859-
Node.Index := Node.PrevSibling.Index + 1
13859+
Node.SetIndex(Node.PrevSibling.Index + 1)
1386013860
else
13861-
Node.Index := 0;
13861+
Node.SetIndex(0);
1386213862
end;
1386313863
else
1386413864
// amNoWhere: do nothing
@@ -13972,7 +13972,7 @@ procedure TBaseVirtualTree.InternalDisconnectNode(Node: PVirtualNode; KeepFocus:
1397213972
Index := Node.Index;
1397313973
while Assigned(Run) do
1397413974
begin
13975-
Run.Index := Index;
13975+
Run.SetIndex(Index);
1397613976
System.Inc(Index);
1397713977
Run := Run.NextSibling;
1397813978
end;
@@ -15131,7 +15131,7 @@ function TBaseVirtualTree.ReadChunk(Stream: TStream; Version: Integer; Node: PVi
1513115131

1513215132
Run.PrevSibling := Node.LastChild;
1513315133
if Assigned(Run.PrevSibling) then
15134-
Run.Index := Run.PrevSibling.Index + 1;
15134+
Run.SetIndex(Run.PrevSibling.Index + 1);
1513515135
if Assigned(Node.LastChild) then
1513615136
Node.LastChild.NextSibling := Run
1513715137
else
@@ -22479,7 +22479,7 @@ procedure TBaseVirtualTree.Sort(Node: PVirtualNode; Column: TColumnIndex; Direct
2247922479
Run.PrevSibling := nil;
2248022480
Index := 0;
2248122481
repeat
22482-
Run.Index := Index;
22482+
Run.SetIndex(Index);
2248322483
System.Inc(Index);
2248422484
if Run.NextSibling = nil then
2248522485
Break;

Source/VirtualTrees.Types.pas

+10-1
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,9 @@ TScrollBarOptions = class(TPersistent)
878878
PVirtualNode = ^TVirtualNode;
879879

880880
TVirtualNode = packed record
881-
Index, // index of node with regard to its parent
881+
private
882+
fIndex: Cardinal; // index of node with regard to its parent
883+
public
882884
ChildCount: Cardinal; // number of child nodes
883885
NodeHeight: TDimension; // height in pixels
884886
States: TVirtualNodeStates; // states describing various properties of the node (expanded, initialized etc.)
@@ -901,6 +903,8 @@ TScrollBarOptions = class(TPersistent)
901903
FirstChild, // link to the node's first child...
902904
LastChild: PVirtualNode; // link to the node's last child...
903905
procedure SetParent(const pParent: PVirtualNode); inline; //internal method, do not call directly but use Parent[Node] := x on tree control.
906+
procedure SetIndex(const pIndex: Cardinal); inline; //internal method, do not call directly.
907+
property Index: Cardinal read fIndex;
904908
property Parent: PVirtualNode read fParent;
905909
private
906910
Data: record end; // this is a placeholder, each node gets extra data determined by NodeDataSize
@@ -1169,6 +1173,11 @@ procedure TVirtualNode.SetData<T>(pUserData: T);
11691173
Include(Self.States, vsOnFreeNodeCallRequired);
11701174
end;
11711175

1176+
procedure TVirtualNode.SetIndex(const pIndex: Cardinal);
1177+
begin
1178+
fIndex := pIndex;
1179+
end;
1180+
11721181
procedure TVirtualNode.SetParent(const pParent: PVirtualNode);
11731182
begin
11741183
fParent := pParent;

0 commit comments

Comments
 (0)