Skip to content

Commit 990c552

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

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Source/VirtualTrees.BaseTree.pas

+7-7
Original file line numberDiff line numberDiff line change
@@ -5062,7 +5062,7 @@ procedure TBaseVirtualTree.SetChildCount(Node: PVirtualNode; NewChildCount: Card
50625062
AdjustTotalHeight(Node, NewHeight, False);
50635063

50645064
AdjustTotalCount(Node, Count, True);
5065-
Node.ChildCount := NewChildCount;
5065+
Node.SetChildCount(NewChildCount);
50665066
if (FUpdateCount = 0) and (toAutoSort in FOptions.AutoOptions) and (FHeader.SortColumn > InvalidColumn) then
50675067
Sort(Node, FHeader.SortColumn, FHeader.SortDirection, True);
50685068

@@ -5687,7 +5687,7 @@ procedure TBaseVirtualTree.SetRootNodeCount(Value: Cardinal);
56875687
// Don't set the root node count until all other properties (in particular the OnInitNode event) have been set.
56885688
if csLoading in ComponentState then
56895689
begin
5690-
FRoot.ChildCount := Value;
5690+
FRoot.SetChildCount(Value);
56915691
DoStateChange([tsNeedRootCountUpdate]);
56925692
end
56935693
else
@@ -13864,7 +13864,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
1386413864
Node.States := Node.States - [vsChecking, vsCutOrCopy, vsDeleting];
1386513865

1386613866
if (Mode <> amNoWhere) then begin
13867-
System.Inc(Node.Parent.ChildCount);
13867+
Node.Parent.SetChildCount(Node.Parent.ChildCount + 1);
1386813868
Include(Node.Parent.States, vsHasChildren);
1386913869
AdjustTotalCount(Node.Parent, Node.TotalCount, True);
1387013870

@@ -13940,7 +13940,7 @@ procedure TBaseVirtualTree.InternalDisconnectNode(Node: PVirtualNode; KeepFocus:
1394013940
// Some states are only temporary so take them out.
1394113941
Node.States := Node.States - [vsChecking];
1394213942
Parent := Node.Parent;
13943-
System.Dec(Parent.ChildCount);
13943+
Parent.SetChildCount(Parent.ChildCount - 1);
1394413944
AdjustHeight := (vsExpanded in Parent.States) and (vsVisible in Node.States);
1394513945
if Parent.ChildCount = 0 then
1394613946
begin
@@ -14073,7 +14073,7 @@ procedure TBaseVirtualTree.Loaded;
1407314073
IsReadOnly := toReadOnly in FOptions.MiscOptions;
1407414074
FOptions.InternalSetMiscOptions(FOptions.MiscOptions - [toReadOnly]);
1407514075
LastRootCount := FRoot.ChildCount;
14076-
FRoot.ChildCount := 0;
14076+
FRoot.SetChildCount(0);
1407714077
BeginUpdate;
1407814078
SetChildCount(FRoot, LastRootCount);
1407914079
EndUpdate;
@@ -15119,7 +15119,7 @@ function TBaseVirtualTree.ReadChunk(Stream: TStream; Version: Integer; Node: PVi
1511915119
Align := ChunkBody.Align;
1512015120
CheckState := ChunkBody.CheckState;
1512115121
CheckType := ChunkBody.CheckType;
15122-
ChildCount := ChunkBody.ChildCount;
15122+
SetChildCount(ChunkBody.ChildCount);
1512315123

1512415124
// Create and read child nodes.
1512515125
while ChunkBody.ChildCount > 0 do
@@ -16901,7 +16901,7 @@ procedure TBaseVirtualTree.DeleteChildren(Node: PVirtualNode; ResetHasChildren:
1690116901
Exclude(Node.States, vsHasChildren);
1690216902
if Node <> FRoot then
1690316903
Exclude(Node.States, vsExpanded);
16904-
Node.ChildCount := 0;
16904+
Node.SetChildCount(0);
1690516905
if (Node = FRoot) or (vsDeleting in Node.States) then
1690616906
begin
1690716907
Node.TotalHeight := FDefaultNodeHeight + NodeHeight[Node];

Source/VirtualTrees.Types.pas

+8-1
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,8 @@ TScrollBarOptions = class(TPersistent)
886886
TVirtualNode = packed record
887887
private
888888
fIndex: Cardinal; // index of node with regard to its parent
889+
fChildCount: Cardinal; // number of child nodes
889890
public
890-
ChildCount: Cardinal; // number of child nodes
891891
NodeHeight: TDimension; // height in pixels
892892
States: TVirtualNodeStates; // states describing various properties of the node (expanded, initialized etc.)
893893
Align: Byte; // line/button alignment
@@ -916,7 +916,9 @@ TScrollBarOptions = class(TPersistent)
916916
procedure SetFirstChild(const pFirstChild: PVirtualNode); inline; //internal method, do not call directly
917917
procedure SetLastChild(const pLastChild: PVirtualNode); inline; //internal method, do not call directly
918918
procedure SetIndex(const pIndex: Cardinal); inline; //internal method, do not call directly.
919+
procedure SetChildCount(const pCount: Cardinal); inline; //internal method, do not call directly.
919920
property Index: Cardinal read fIndex;
921+
property ChildCount: Cardinal read fChildCount;
920922
property Parent: PVirtualNode read fParent;
921923
property PrevSibling: PVirtualNode read fPrevSibling;
922924
property NextSibling: PVirtualNode read fNextSibling;
@@ -1164,6 +1166,11 @@ procedure TVirtualNode.SetData(pUserData: Pointer);
11641166

11651167
//----------------------------------------------------------------------------------------------------------------------
11661168

1169+
procedure TVirtualNode.SetChildCount(const pCount: Cardinal);
1170+
begin
1171+
fChildCount := pCount;
1172+
end;
1173+
11671174
procedure TVirtualNode.SetData(const pUserData: IInterface);
11681175

11691176

0 commit comments

Comments
 (0)