Skip to content

Commit

Permalink
Change for #832: Turn TVirtualNode.PrevSibling into a readonly property.
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmarder committed Aug 1, 2023
1 parent 6ed0528 commit f696bb6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
28 changes: 14 additions & 14 deletions Source/VirtualTrees.BaseTree.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4322,7 +4322,7 @@ procedure TBaseVirtualTree.InitRootNode(OldSize: Cardinal = 0);
with FRoot^ do
begin
// Indication that this node is the root node.
PrevSibling := FRoot;
SetPrevSibling(FRoot);
NextSibling := FRoot;
SetParent(Pointer(Self));
States := [vsInitialized, vsExpanded, vsHasChildren, vsVisible];
Expand Down Expand Up @@ -5042,7 +5042,7 @@ procedure TBaseVirtualTree.SetChildCount(Node: PVirtualNode; NewChildCount: Card
begin
Child := MakeNewNode;
Child.SetIndex(Index);
Child.PrevSibling := Node.LastChild;
Child.SetPrevSibling(Node.LastChild);
if Assigned(Node.LastChild) then
Node.LastChild.NextSibling := Child;
Child.SetParent(Node);
Expand Down Expand Up @@ -13753,8 +13753,8 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
case Mode of
amInsertBefore:
begin
Node.PrevSibling := Destination.PrevSibling;
Destination.PrevSibling := Node;
Node.SetPrevSibling(Destination.PrevSibling);
Destination.SetPrevSibling(Node);
Node.NextSibling := Destination;
Node.SetParent(Destination.Parent);
Node.SetIndex(Destination.Index);
Expand All @@ -13775,12 +13775,12 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
begin
Node.NextSibling := Destination.NextSibling;
Destination.NextSibling := Node;
Node.PrevSibling := Destination;
Node.SetPrevSibling(Destination);
Node.SetParent(Destination.Parent);
if Node.NextSibling = nil then
Node.Parent.LastChild := Node
else
Node.NextSibling.PrevSibling := Node;
Node.NextSibling.SetPrevSibling(Node);
Node.SetIndex(Destination.Index);

// reindex all following nodes
Expand All @@ -13796,7 +13796,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
if Assigned(Destination.FirstChild) then
begin
// If there's a first child then there must also be a last child.
Destination.FirstChild.PrevSibling := Node;
Destination.FirstChild.SetPrevSibling(Node);
Node.NextSibling := Destination.FirstChild;
Destination.FirstChild := Node;
end
Expand All @@ -13807,7 +13807,7 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
Destination.LastChild := Node;
Node.NextSibling := nil;
end;
Node.PrevSibling := nil;
Node.SetPrevSibling(nil);
Node.SetParent(Destination);
Node.SetIndex(0);
// reindex all following nodes
Expand All @@ -13824,15 +13824,15 @@ procedure TBaseVirtualTree.InternalConnectNode(Node, Destination: PVirtualNode;
begin
// If there's a last child then there must also be a first child.
Destination.LastChild.NextSibling := Node;
Node.PrevSibling := Destination.LastChild;
Node.SetPrevSibling(Destination.LastChild);
Destination.LastChild := Node;
end
else
begin
// first child node at this location
Destination.FirstChild := Node;
Destination.LastChild := Node;
Node.PrevSibling := nil;
Node.SetPrevSibling(nil);
end;
Node.NextSibling := nil;
Node.SetParent(Destination);
Expand Down Expand Up @@ -13945,7 +13945,7 @@ procedure TBaseVirtualTree.InternalDisconnectNode(Node: PVirtualNode; KeepFocus:

if Assigned(Node.NextSibling) then
begin
Node.NextSibling.PrevSibling := Node.PrevSibling;
Node.NextSibling.SetPrevSibling(Node.PrevSibling);
// Reindex all following nodes.
if Reindex then
begin
Expand Down Expand Up @@ -15110,7 +15110,7 @@ function TBaseVirtualTree.ReadChunk(Stream: TStream; Version: Integer; Node: PVi
begin
Run := MakeNewNode;

Run.PrevSibling := Node.LastChild;
Run.SetPrevSibling(Node.LastChild);
if Assigned(Run.PrevSibling) then
Run.SetIndex(Run.PrevSibling.Index + 1);
if Assigned(Node.LastChild) then
Expand Down Expand Up @@ -22461,14 +22461,14 @@ procedure TBaseVirtualTree.Sort(Node: PVirtualNode; Column: TColumnIndex; Direct
end;
// Consolidate the child list finally.
Run := Node.FirstChild;
Run.PrevSibling := nil;
Run.SetPrevSibling(nil);
Index := 0;
repeat
Run.SetIndex(Index);
System.Inc(Index);
if Run.NextSibling = nil then
Break;
Run.NextSibling.PrevSibling := Run;
Run.NextSibling.SetPrevSibling(Run);
Run := Run.NextSibling;
until False;
Node.LastChild := Run;
Expand Down
11 changes: 9 additions & 2 deletions Source/VirtualTrees.Types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -902,16 +902,18 @@ TScrollBarOptions = class(TPersistent)
// located at the end of the node! Hence if you want to add new member fields (except pointers to internal
// data) then put them before field Parent.
private
fParent: PVirtualNode; // link to the node's last child...
fParent: PVirtualNode; // link to the node's last child...
fPrevSibling: PVirtualNode; // link to the node's previous sibling or nil if it is the first node
public // reference to the node's parent (for the root this contains the treeview)
PrevSibling, // link to the node's previous sibling or nil if it is the first node
NextSibling, // link to the node's next sibling or nil if it is the last node
FirstChild, // link to the node's first child...
LastChild: PVirtualNode; // link to the node's last child...
procedure SetParent(const pParent: PVirtualNode); inline; //internal method, do not call directly but use Parent[Node] := x on tree control.
procedure SetPrevSibling(const pPrevSibling: PVirtualNode); inline; //internal method, do not call directly
procedure SetIndex(const pIndex: Cardinal); inline; //internal method, do not call directly.
property Index: Cardinal read fIndex;
property Parent: PVirtualNode read fParent;
property PrevSibling: PVirtualNode read fPrevSibling;
private
Data: record end; // this is a placeholder, each node gets extra data determined by NodeDataSize
public
Expand Down Expand Up @@ -1188,6 +1190,11 @@ procedure TVirtualNode.SetParent(const pParent: PVirtualNode);
fParent := pParent;
end;

procedure TVirtualNode.SetPrevSibling(const pPrevSibling: PVirtualNode);
begin
fPrevSibling := pPrevSibling;
end;

//----------------------------------------------------------------------------------------------------------------------


Expand Down

0 comments on commit f696bb6

Please sign in to comment.