Units
Classes, Interfaces, Objects
Types
Variables
Constants
Functions, Procedures
Identifiers

Class TExTree

Unit

rjExTrees

Declaration

type TExTree = class(TExContainer)

Description

TExTree is the base class for all n-ary tree containers. It provides basic tree functionality like inserting, deleting and navigating.

Inserting Deleting Navigating
InsertItemFirst
InsertItemLast

InsertItemBefore
InsertItemAfter

InsertItemChildFirst
InsertItemChildLast
Clear
Delete
DeleteChildren
FirstItem
FirstSiblingItem
FirstChildItem
FirstGrandChildItem

LastItem
LastSiblingItem
LastChildItem
LastGrandChildItem

NextItem
NextSiblingItem

PreviousItem
PreviousSiblingItem

ParentItem

Hierarchy

TExContainer > TErrorObject

Fields

NameDescription
FRootNode  

Methods

Overview

constructor Create; override;
destructor Destroy; override;
procedure Clear; virtual;
procedure Delete(const PItem: Pointer);
procedure DeleteChildren(const PItem: Pointer);
function HasAsParent(const PItem, PPotentialParentItem: Pointer): Boolean;
function InsertItemAfter(const PItem: Pointer): Pointer;
function InsertItemBefore(const PItem: Pointer): Pointer;
function InsertItemChildFirst(const PItem: Pointer): Pointer;
function InsertItemChildLast(const PItem: Pointer): Pointer;
function InsertItemFirst: Pointer;
function InsertItemLast: Pointer;
procedure InternalConnectNodeAfter(const PNode, PDestinationNode: PTreeNode);
procedure InternalConnectNodeBefore(const PNode, PDestinationNode: PTreeNode);
procedure InternalConnectNodeChildFirst(const PNode, PDestinationNode: PTreeNode);
procedure InternalConnectNodeChildLast(const PNode, PDestinationNode: PTreeNode);
procedure InternalDeleteChildren(const PNode: PTreeNode);
procedure InternalDisconnectNode(const PNode: PTreeNode);
function InternalNextNode(const PNode: PTreeNode): PTreeNode;
function InternalPreviousNode(const PNode: PTreeNode): PTreeNode;
function IterateChildren(const PStartItem, PExtraData: Pointer; const CallBack: TExIterateProc): Pointer;
function Level(const PItem: Pointer): Cardinal;
procedure MoveAfter(const PSourceItem, PTargetItem: Pointer);
procedure MoveBefore(const PSourceItem, PTargetItem: Pointer);
procedure MoveChildFirst(const PSourceItem, PTargetItem: Pointer);
procedure MoveChildLast(const PSourceItem, PTargetItem: Pointer);
function PFirstChildItem(const PItem: Pointer): Pointer;
function PFirstGrandChildItem(const PItem: Pointer): Pointer;
function PFirstItem: Pointer;
function PFirstSiblingItem(const PItem: Pointer): Pointer;
function PItemBackOf(const PExtraData: Pointer; const Same: TExSameItemsFunc): Pointer;
function PItemOf(const PExtraData: Pointer; const Same: TExSameItemsFunc): Pointer;
function PLastChildItem(const PItem: Pointer): Pointer;
function PLastGrandChildItem(const PItem: Pointer): Pointer;
function PLastItem: Pointer;
function PLastSiblingItem(const PItem: Pointer): Pointer;
function PNextItem(const PItem: Pointer): Pointer;
function PNextSiblingItem(const PItem: Pointer): Pointer;
function PParentItem(const PItem: Pointer): Pointer;
function PPreviousItem(const PItem: Pointer): Pointer;
function PPreviousSiblingItem(const PItem: Pointer): Pointer;

Description

constructor Create; override;

 

destructor Destroy; override;

Destroys an instance of TExTree.

procedure Clear; virtual;

Deletes all Items from a tree container.

If OnFreeItem is assigned, it will be called for each Item starting with the first and all Items will be freed / finalized accordingly.

procedure Delete(const PItem: Pointer);

Deletes Item and all its children from the tree.

procedure DeleteChildren(const PItem: Pointer);

Deletes all children of Item and their children from the tree.

function HasAsParent(const PItem, PPotentialParentItem: Pointer): Boolean;

Returns True if Item has PotentialParentItem as one of its parents.

function InsertItemAfter(const PItem: Pointer): Pointer;

Inserts a new Item after Item into the tree and returns a pointer to it. The new Item will be the next sibling of Item. If Item is nil, the new Item will be inserted as the last Item at root level.

function InsertItemBefore(const PItem: Pointer): Pointer;

Inserts a new Item before Item into the tree and returns a pointer to it. The new Item will be the previous sibling of Item.

If Item is nil, the new Item will be inserted as the first Item at root level. This corresponds to a call of InsertItemFirst.

function InsertItemChildFirst(const PItem: Pointer): Pointer;

Inserts a new Item as the first child of Item into the tree and returns a pointer to it. The new Item will be the first child of Item.

If Item is nil, the new Item will be inserted as the first child of root, which is like calling the preferred method InsertItemFirst.

function InsertItemChildLast(const PItem: Pointer): Pointer;

Inserts a new Item as the last child of Item into the tree and returns a pointer to it. The new Item will be the first child of Item.

If Item is nil, the new Item will be inserted as the first child of root, which is like calling the preferred method InsertItemLast.

function InsertItemFirst: Pointer;

Inserts a new Item as the first Item into the tree and returns a pointer to it. The new Item will be the first Item at root level.

function InsertItemLast: Pointer;

Inserts a new Item as the last Item of root into the tree and returns a pointer to it.

procedure InternalConnectNodeAfter(const PNode, PDestinationNode: PTreeNode);

Connects PNode after PDestinationNode. Internal use only.

procedure InternalConnectNodeBefore(const PNode, PDestinationNode: PTreeNode);

Connects PNode before PDestinationNode. Internal use only.

procedure InternalConnectNodeChildFirst(const PNode, PDestinationNode: PTreeNode);

Connects PNode as the first child of PDestinationNode. Internal use only.

procedure InternalConnectNodeChildLast(const PNode, PDestinationNode: PTreeNode);

Connects PNode as the last child of PDestinationNode. Internal use only.

procedure InternalDeleteChildren(const PNode: PTreeNode);

Deletes all the children and their children of PNode. Internal use only.

procedure InternalDisconnectNode(const PNode: PTreeNode);

Disconnects PNode from its parent, siblings and children. Internal use only.

function InternalNextNode(const PNode: PTreeNode): PTreeNode;

Returns a pointer to the next Node of PNode to walk the tree from top to bottom. Internal use only.

function InternalPreviousNode(const PNode: PTreeNode): PTreeNode;

Returns a pointer to the previous Node of PNode to walk the tree from bottom to top. Internal use only.

function IterateChildren(const PStartItem, PExtraData: Pointer; const CallBack: TExIterateProc): Pointer;

Iterates through all children and grandchildren of PStartItem and calls Callback for each item encountered starting with the first Item. CallBack must be assigned or an exception will be raised if the rjExContainer Library was compiled with the directive "RangeChecking" defined (default).

Iteration continues as long as Callback does not set its Abort parameter to true. Otherwise, iteration stops and returns a pointer to the current Item. If not stopped, IterateChildren> returns nil.

Use PExtraData to pass additional information to Callback. To iterate over the entire tree, set PStartItem to nil.

function Level(const PItem: Pointer): Cardinal;

Returns the level of the given Item.

procedure MoveAfter(const PSourceItem, PTargetItem: Pointer);

Moves the Item pointed to by PSourceItem after the Item pointed to by PTargetItem.

procedure MoveBefore(const PSourceItem, PTargetItem: Pointer);

Moves the Item pointed to by PSourceItem before the Item pointed to by PTargetItem.

procedure MoveChildFirst(const PSourceItem, PTargetItem: Pointer);

Moves the Item pointed to by PSourceItem to the front of the children of PTargetItem.

procedure MoveChildLast(const PSourceItem, PTargetItem: Pointer);

Moves the Item pointed to by PSourceItem to the end of the children of PTargetItem.

function PFirstChildItem(const PItem: Pointer): Pointer;

Returns a pointer to the first child of Item. If Item does not have any children, PFirstChildItem> returns nil.

If Item is nil, PFirstChildItem> returns a pointer to the first child of the tree's root, if it exists.

function PFirstGrandChildItem(const PItem: Pointer): Pointer;

Returns a pointer to the first child of the first child of Item all the way down the tree until the very last first child if Item is reached. If Item does not have any children, PFirstGrandChildItem> returns nil.

function PFirstItem: Pointer;

Returns a pointer to the very first Item in the tree. If the tree is empty, PFirstItem> returns nil.

function PFirstSiblingItem(const PItem: Pointer): Pointer;

Returns a pointer to the first sibling of Item in the tree. If Item is nil, the result is also nil, because nil represents root which does not have any siblings.

In case Item is the first of its siblings or does not have any siblings, PFirstSiblingItem> returns Item.

function PItemBackOf(const PExtraData: Pointer; const Same: TExSameItemsFunc): Pointer;

Returns the Item matching PExtraData via the Same function. PItemBackOf> will iterate over all Items in the container starting with the last one until it found a matching Item and return a pointer to it. If there is no match, PItemBackOf> returns nil.

See also:

function PItemOf(const PExtraData: Pointer; const Same: TExSameItemsFunc): Pointer;

Returns the Item matching PExtraData via the Same function. PItemOf> will iterate over all Items in the container starting with the first one until it found a matching Item and return a pointer to it. If there is no match, PItemOf> returns nil.

See also:

function PLastChildItem(const PItem: Pointer): Pointer;

Returns a pointer to the last direct child of Item. If Item does not have any children, PLastChildItem> returns nil.

If Item is nil, PLastChildItem> returns a pointer to the last child of the tree's root, if it exists.

function PLastGrandChildItem(const PItem: Pointer): Pointer;

Returns a pointer to the last child of the last child of Item all the way down the tree until the very last child if Item is reached. If Item does not have any children, PLastGrandChildItem> returns nil.

function PLastItem: Pointer;

Returns a pointer to the very last Item in the tree. To do so, PLastItem> iterates the last child of the last child of the root's last child and so on. If the tree is empty, PLastItem> returns nil.

function PLastSiblingItem(const PItem: Pointer): Pointer;

Returns a pointer to the last sibling of Item in the tree. If Item is nil, the result is also nil, because nil represents root which does not have any siblings.

In case Item is the last of its siblings or does not have any siblings, PLastSiblingItem> returns Item.

function PNextItem(const PItem: Pointer): Pointer;

Returns a pointer to the next Item in the tree with regard to Item. Advances to next sibling of the Item's parent or its parent, if necessary.

function PNextSiblingItem(const PItem: Pointer): Pointer;

Returns a pointer to the next sibling of Item.

function PParentItem(const PItem: Pointer): Pointer;

Returns a pointer to the Item's parent. If Item does not have a parent (which means that it is at level 1), PParentItem> returns nil.

function PPreviousItem(const PItem: Pointer): Pointer;

Returns a pointer to the previous Item in the tree with regard to Item. Advances to previous sibling of the Item's parent or its parent, if necessary.

function PPreviousSiblingItem(const PItem: Pointer): Pointer;

Returns a pointer to the previous sibling of Item.

Properties

None.


rjExContainer Library Version 0.2.
Copyright Ralf Junker 2000-2001.
http://www.zeitungsjunge.de/delphi/.