Skip to main content

Overview

TTree (and its base class TCustomTree) is the main visual component in TeeTree. It maintains a network-hierarchy of nodes, similar to Microsoft TreeView, but with enhanced features. Each node is a full standalone component with properties, methods, and events.

Class Hierarchy

TCustomTeePanelExtended
  └─ TCustomTree
      └─ TTree

Key Features

  • Hierarchical node structure with parent-child relationships
  • Visual connections between nodes
  • Multiple selection support
  • Drag and drop functionality
  • Zoom and pan capabilities
  • Grid display options
  • Custom node shapes and styles
  • Database integration (via TDBTree)

Properties

Core Properties

Roots
TNodeShapeList
List of root-level nodes in the tree. Root nodes have no parent.
Shapes
TTreeShapeList
Collection of all nodes in the tree, regardless of hierarchy.
Selected
TSelectedShapeList
List of currently selected nodes and selection formatting options.
Connections
TTreeConnectionList
List of all connection objects that link nodes together.

Display Properties

ShowText
Boolean
default:"True"
When True, node text is displayed.
ShowImages
Boolean
default:"True"
When True, node images are displayed.
ShowHintShapes
Boolean
default:"True"
When True, shows hints when hovering over nodes.
ShowRootCross
Boolean
default:"True"
When True, displays expand/collapse cross-box for root nodes.
BufferedDisplay
Boolean
default:"True"
When True, uses double-buffering for smoother display.

Interaction Properties

AllowDelete
Boolean
default:"True"
When True, allows users to delete nodes using the Delete key.
AllowResize
Boolean
default:"True"
When True, allows users to resize nodes by dragging handles.
ReadOnly
Boolean
default:"False"
When True, prevents editing of node positions and text.
SingleSelection
Boolean
default:"True"
When True, only one node can be selected at a time.
SnapToGrid
Boolean
default:"True"
When True, nodes snap to grid when moved.
Navigation
TTreeNavigation
default:"tnExplorer"
Keyboard navigation style: tnExplorer, tnNearest, tnNone, or tnCircularExplorer.
WheelNavigation
TTreeWheelNavigation
default:"wnSelection"
Mouse wheel behavior: wnSelection, wnScrollVert, wnScrollHoriz, wnZoom, or wnNone.

Visual Components

CrossBox
TTreeNodeCrossBox
Configuration for the expand/collapse cross-box displayed on nodes with children.
Grid
TTreeGrid
Grid display options including step size, color, and visibility.
HotTrack
TTreeHotTrack
Highlight settings when hovering over nodes.
Page
TTreePage
Page size and boundary configuration for printing.
Images
TImageList
Image list for node icons.

Scrolling

HorzScrollBar
TTeeScrollBar
Horizontal scrollbar configuration.
VertScrollBar
TTeeScrollBar
Vertical scrollbar configuration.
ScrollMouseButton
TMouseButton
default:"mbRight"
Mouse button used for panning: mbLeft, mbRight, or mbMiddle.

Drag and Drop

DragAndDrop
TTreeDragDrop
Automatic drag and drop configuration.

Text Editing

TextEditor
TTreeTextEditor
Configuration for inline text editing with a memo control.

Advanced Properties

GlobalFormat
TTreeGlobal
Global formatting settings applied to all new nodes, including default border, brush, font, and child manager.
Designing
Boolean
default:"False"
When True, enables design-time features at runtime.
AssignParent
Boolean
default:"False"
When True, newly added nodes copy format from their parent node.
CreateConnections
Boolean
default:"False"
When True, adding a child node automatically creates a connection object.
NoOwnerShapes
Boolean
default:"False"
When True, new nodes are created without VCL Owner (nil).
ZoomCentered
Boolean
default:"False"
When True, zoom operations center on the current view.

Methods

Adding Nodes

Add
function
Adds a new node to the tree.Overloads:
function Add(const Text: String): TTreeNodeShape;
function Add(const Text: String; const Parent: TTreeNodeShape): TTreeNodeShape;
function Add(X, Y: Integer; const Text: String; const Parent: TTreeNodeShape): TTreeNodeShape;
Parameters:
  • Text - Text to display in the node
  • Parent - Optional parent node
  • X, Y - Optional position coordinates
Returns: The newly created node
AddRoot
function
Adds a new root-level node.
function AddRoot(const RootText: String): TTreeNodeShape;
Parameters:
  • RootText - Text to display in the root node
Returns: The newly created root node
AddShape
function
Adds a new node at specific coordinates.
function AddShape(X, Y: Integer; const AText: String; const AParentShape: TTreeNodeShape): TTreeNodeShape;
AddShapeClass
function
Adds a new node using a specific node class.
function AddShapeClass(X, Y: Integer; const AText: String; const AParentShape: TTreeNodeShape; const AClass: TTreeNodeShapeClass): TTreeNodeShape;

Node Management

DeleteShape
procedure
Deletes a node and all its children.
procedure DeleteShape(const AShape: TTreeNodeShape);
Clear
procedure
Removes all nodes from the tree.
procedure Clear;
CloneShape
function
Creates a copy of a node.
function CloneShape(const AShape: TTreeNodeShape): TTreeNodeShape;
ClickedShape
function
Finds the node at the specified coordinates.
function ClickedShape(x, y: Integer): TTreeNodeShape;
Returns: Node at coordinates, or nil if none

Selection

SelectConnection
procedure
Selects a connection.
procedure SelectConnection(const AConnection: TTreeConnection);

Expand/Collapse

FullExpandCollapse
procedure
Expands or collapses all nodes.
procedure FullExpandCollapse(Expand: Boolean);

Zoom and View

ZoomRectangle
procedure
Zooms to fit a specific rectangle.
procedure ZoomRectangle(R: TRect);
ZoomFromCenter
procedure
Zooms from a specific point.
procedure ZoomFromCenter(NewZoom: Integer; X, Y: Integer);
ZoomReset
procedure
Resets zoom to 100%.
procedure ZoomReset;
ZoomSetHome
procedure
Saves current zoom and position as default.
procedure ZoomSetHome;
procedure ZoomSetHome(const ZoomParams: TTreeZoomDefault);
CenterInView
procedure
Centers a node in the viewport.
procedure CenterInView(const Shape: TTreeNodeShape; Animated: Boolean = True);

Text Editing

StartEditing
procedure
Begins editing a node’s text.
procedure StartEditing(const AShape: TTreeNodeShape);
StopEditing
procedure
Stops text editing.
procedure StopEditing;

Sorting

Sort
procedure
Sorts all nodes alphabetically.
procedure Sort(Ascending: Boolean = True; IgnoreCase: Boolean = True);

Loading and Saving

LoadFromTextFile
function
Loads tree structure from a text file.
function LoadFromTextFile(const FileName: String): TTreeNodeShape;
LoadFromStrings
function
Loads tree structure from string list.
function LoadFromStrings(const Strings: TStrings): TTreeNodeShape;

Drawing

BeginUpdate
procedure
Suspends drawing to improve performance during batch operations.
procedure BeginUpdate;
EndUpdate
procedure
Resumes drawing after BeginUpdate.
procedure EndUpdate;

Events

Node Events

OnClickShape
TClickShapeEvent
Fired when a node is clicked.
property OnClickShape: TClickShapeEvent;
// procedure(Sender: TTreeNodeShape; Button: TMouseButton; Shift: TShiftState; X, Y: Integer)
OnDblClickShape
TClickShapeEvent
Fired when a node is double-clicked.
OnSelectShape
TNotifyShapeEvent
Fired when a node is selected.
property OnSelectShape: TNotifyShapeEvent;
// procedure(Sender: TTreeNodeShape)
OnUnSelectShape
TNotifyShapeEvent
Fired when a node is deselected.
OnNewShape
TTreeNewShapeEvent
Fired when a new node is created.
property OnNewShape: TTreeNewShapeEvent;
// procedure(Sender: TCustomTreePanel; NewShape: TTreeNodeShape)
OnMovingShape
TMovingShapeEvent
Fired when a node is being moved.
property OnMovingShape: TMovingShapeEvent;
// procedure(Sender: TTreeNodeShape; var DeltaX, DeltaY: Integer)
OnResizingShape
TTreeResizingShape
Fired when a node is being resized.
property OnResizingShape: TTreeResizingShape;
// procedure(Sender: TTreeNodeShape; ACorner: TTreeShapeHandle; var DeltaX, DeltaY: Integer)
OnMouseEnterShape
TMouseShapeEvent
Fired when mouse enters a node.
OnMouseLeaveShape
TMouseShapeEvent
Fired when mouse leaves a node.

Expand/Collapse Events

OnExpandingCollapsing
TExpandingCollapsingEvent
Fired before a node expands or collapses. Can be cancelled.
property OnExpandingCollapsing: TExpandingCollapsingEvent;
// procedure(Sender: TTreeNodeShape; var Expand: Boolean)
OnExpandedCollapsed
TNotifyShapeEvent
Fired after a node has expanded or collapsed.

Connection Events

OnClickConnection
TClickConnectionEvent
Fired when a connection is clicked.
OnDblClickConnection
TClickConnectionEvent
Fired when a connection is double-clicked.
OnNewConnection
TTreeNewConnectionEvent
Fired when a new connection is created.
OnSelectConnection
TNotifyConnectionEvent
Fired when a connection is selected.
OnAddingConnection
TTreeAddingConnectionEvent
Fired before a connection is added. Can be cancelled.
property OnAddingConnection: TTreeAddingConnectionEvent;
// procedure(Node1, Node2: TTreeNodeShape; var Add: Boolean)

Edit Events

OnStartEditing
TNotifyShapeEventStartEdit
Fired before editing begins. Can be cancelled.
property OnStartEditing: TNotifyShapeEventStartEdit;
// procedure(Shape: TTreeNodeShape; var AllowEditing: Boolean)
OnStopEditing
TNotifyShapeEvent
Fired when editing ends.

Delete Events

OnDeletingShapes
TDeleteShapesEvent
Fired before nodes are deleted. Can be cancelled.
property OnDeletingShapes: TDeleteShapesEvent;
// procedure(Sender: TSelectedShapeList; var AllowDelete: Boolean)
OnDeletedShapes
TNotifyEvent
Fired after nodes have been deleted.

Drag and Drop Events

OnDragDropShape
TDragDropShapeEvent
Fired when a node is dropped.
property OnDragDropShape: TDragDropShapeEvent;
// procedure(Sender: TCustomTree; Dragged, Parent: TTreeNodeShape)

Drawing Events

OnBeforeDraw
TNotifyEvent
Fired before the tree is drawn.
OnAfterDraw
TNotifyEvent
Fired after the tree is drawn.

Other Events

OnChanging
TTreeChangingEvent
Fired before any change. Can be cancelled.
property OnChanging: TTreeChangingEvent;
// procedure(Sender: TCustomTree; Node: TTreeNodeShape; var Allow: Boolean)
OnClickBackground
TTreeClick
Fired when empty area is clicked.
OnShowHint
TShowHintShapeEvent
Fired when showing a node hint.
property OnShowHint: TShowHintShapeEvent;
// procedure(Sender: TCustomTree; Shape: TTreeNodeShape; var Text: String)
OnCheckedShape
TNotifyEvent
Fired when a node’s checkbox is checked or unchecked.
OnSortCompare
TTreeSortCompareEvent
Fired during sorting to compare two nodes.
property OnSortCompare: TTreeSortCompareEvent;
// procedure(Node1, Node2: TTreeNodeShape; var Compare: Integer)

Usage Examples

Creating a Simple Tree

var
  Root, Child1, Child2: TTreeNodeShape;
begin
  // Create root node
  Root := Tree1.AddRoot('Root');
  
  // Add children
  Child1 := Root.AddChild('Child 1');
  Child2 := Root.AddChild('Child 2');
  
  // Expand root
  Root.Expanded := True;
end;

Handling Node Selection

procedure TForm1.Tree1SelectShape(Sender: TTreeNodeShape);
begin
  ShowMessage('Selected: ' + Sender.Text[0]);
end;

Customizing Node Appearance

var
  Node: TTreeNodeShape;
begin
  Node := Tree1.AddRoot('Custom Node');
  Node.Color := clYellow;
  Node.Border.Color := clBlue;
  Node.Border.Width := 2;
  Node.Font.Style := [fsBold];
  Node.Shadow.Visible := True;
end;

Using Grid and Snap

begin
  Tree1.Grid.Visible := True;
  Tree1.Grid.Step := 20;
  Tree1.SnapToGrid := True;
end;

Batch Operations

var
  i: Integer;
begin
  Tree1.BeginUpdate;
  try
    for i := 1 to 1000 do
      Tree1.AddRoot('Node ' + IntToStr(i));
  finally
    Tree1.EndUpdate;
  end;
end;

See Also

Build docs developers (and LLMs) love