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
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
List of root-level nodes in the tree. Root nodes have no parent.
Collection of all nodes in the tree, regardless of hierarchy.
List of currently selected nodes and selection formatting options.
List of all connection objects that link nodes together.
Display Properties
When True, node text is displayed.
When True, node images are displayed.
When True, shows hints when hovering over nodes.
When True, displays expand/collapse cross-box for root nodes.
When True, uses double-buffering for smoother display.
Interaction Properties
When True, allows users to delete nodes using the Delete key.
When True, allows users to resize nodes by dragging handles.
When True, prevents editing of node positions and text.
When True, only one node can be selected at a time.
When True, nodes snap to grid when moved.
Keyboard navigation style:
tnExplorer, tnNearest, tnNone, or tnCircularExplorer.Mouse wheel behavior:
wnSelection, wnScrollVert, wnScrollHoriz, wnZoom, or wnNone.Visual Components
Configuration for the expand/collapse cross-box displayed on nodes with children.
Grid display options including step size, color, and visibility.
Highlight settings when hovering over nodes.
Page size and boundary configuration for printing.
Image list for node icons.
Scrolling
Horizontal scrollbar configuration.
Vertical scrollbar configuration.
Mouse button used for panning:
mbLeft, mbRight, or mbMiddle.Drag and Drop
Automatic drag and drop configuration.
Text Editing
Configuration for inline text editing with a memo control.
Advanced Properties
Global formatting settings applied to all new nodes, including default border, brush, font, and child manager.
When True, enables design-time features at runtime.
When True, newly added nodes copy format from their parent node.
When True, adding a child node automatically creates a connection object.
When True, new nodes are created without VCL Owner (nil).
When True, zoom operations center on the current view.
Methods
Adding Nodes
Adds a new node to the tree.Overloads:Parameters:
Text- Text to display in the nodeParent- Optional parent nodeX, Y- Optional position coordinates
Adds a new root-level node.Parameters:
RootText- Text to display in the root node
Adds a new node at specific coordinates.
Adds a new node using a specific node class.
Node Management
Deletes a node and all its children.
Removes all nodes from the tree.
Creates a copy of a node.
Finds the node at the specified coordinates.Returns: Node at coordinates, or nil if none
Selection
Selects a connection.
Expand/Collapse
Expands or collapses all nodes.
Zoom and View
Zooms to fit a specific rectangle.
Zooms from a specific point.
Resets zoom to 100%.
Saves current zoom and position as default.
Centers a node in the viewport.
Text Editing
Begins editing a node’s text.
Stops text editing.
Sorting
Sorts all nodes alphabetically.
Loading and Saving
Loads tree structure from a text file.
Loads tree structure from string list.
Drawing
Suspends drawing to improve performance during batch operations.
Resumes drawing after BeginUpdate.
Events
Node Events
Fired when a node is clicked.
Fired when a node is double-clicked.
Fired when a node is selected.
Fired when a node is deselected.
Fired when a new node is created.
Fired when a node is being moved.
Fired when a node is being resized.
Fired when mouse enters a node.
Fired when mouse leaves a node.
Expand/Collapse Events
Fired before a node expands or collapses. Can be cancelled.
Fired after a node has expanded or collapsed.
Connection Events
Fired when a connection is clicked.
Fired when a connection is double-clicked.
Fired when a new connection is created.
Fired when a connection is selected.
Fired before a connection is added. Can be cancelled.
Edit Events
Fired before editing begins. Can be cancelled.
Fired when editing ends.
Delete Events
Fired before nodes are deleted. Can be cancelled.
Fired after nodes have been deleted.
Drag and Drop Events
Fired when a node is dropped.
Drawing Events
Fired before the tree is drawn.
Fired after the tree is drawn.
Other Events
Fired before any change. Can be cancelled.
Fired when empty area is clicked.
Fired when showing a node hint.
Fired when a node’s checkbox is checked or unchecked.
Fired during sorting to compare two nodes.
Usage Examples
Creating a Simple Tree
Handling Node Selection
Customizing Node Appearance
Using Grid and Snap
Batch Operations
See Also
- TTreeNodeShape - Individual tree nodes
- TTreeConnection - Connections between nodes
- TDBTree - Database-aware tree component
