Virtual Treeview is a treeview control built from ground up. More than a decade of development made it one of the most flexible and advanced Delphi tree controls available today. Virtual Treeview started off with the claim to improve many aspects of existing solutions and introduced some new technologies and principles which were not available before.
As the name already indicates, this control uses a different paradigm for tree management than other controls of this kind. It does not know anything about the data it manages (except its size), not even the captions of a node. Everything is retrieved from the application via events (or descendants via overridden methods).
Virtual Treeview has been carefully designed and thoroughly tested. The control proved its concept as well as everyday fitness already in many commercial products and freeware projects.
Note: Virtual Treeview needs Windows XP Theme Manager to compile when used with version 6 (and earlier) of Delphi and Borland C++ Builder! You can disable XP theme support, though, to avoid the need for this extra package. Beginning with Delphi 7 Delphi Gems Themes Services are integral part of the VCL so you do not need the extra Theme Manager package with this or any following version.
Public source code repository and issue tracker
Virtual Treeview is hosted on Google Code , which uses Subversion as SCM. The repository is world-readable and so everybody can get the latest code from there. Also issues should be reported there.
Starting with version 5.0 Virtual Treeview no longer comes with an own setup program because there is a set of design and runtime packages for each supported IDE version, which can easily be opened to compile and install the control in the IDE. Virtual Treeview supports the following IDEs (and their associated VCLs):
Embacadero's RAD Studio XE - XE4
A list of important features
Virtual Treeview is extremely fast. Adding one million nodes takes only 700 milliseconds* ! This made it the fastest treeview publicly available on the Delphi/BCB market already 10 years ago.
Virtual Treeview has a very small memory foot print. by only allocating about 60 bytes per node (in the string tree, the base tree uses only 56 bytes) it is well prepared to hold a million of them.
Virtual Treeview is optimized for high speed access. It takes as few as 0.5 seconds to traverse one million nodes* depending on needed validation and node validation states.
Multiselection is supported, including constrained selection so that only nodes of a certain initial level can be selected. A lot of effort has been put into the development of effective algorithms e.g. to allow for modifying an already large selection set still interactively.
Drawing the entire tree to a bitmap or the printer is supported by the central TBaseVirtualTree.PaintTree method. The messages WM_PRINT and WM_PRINTCLIENT are handled correctly which allow things like drawing a tree into a bitmap (e.g. for layered windows or to implement animated drop down of controls which use VT as drop down control).
There is an TBaseVirtualTree.OnHint event to display node specific hints.
There is an TBaseVirtualTree.OnGetHelpContext event to retrieve node specific help context IDs. This includes automatic tree and window parent control traversal as is invoked when the user pressed F1
There is an TBaseVirtualTree.OnGetPopupMenu event to retrieve node specific popup menus, includes automatic tree traversal.
Middle and right mouse buttons can be used in addition to the left button and support everything which is possible with the left button (dragging, selection etc.). These alternative buttons can be switched, of course.
A fixed background image can be used in the tree and can be given a certain offset, e.g. to simulate shared backgrounds.
Hot style for nodes is supported (just like links in a browser window). A special cursor can be assigned for this task.
String trees support socalled static text which appears after a node's caption (in every column) and which can be formatted differently to the caption but cannot be edited, selected etc.
An auto span column mode is supported which allows a column to take up more space for its caption if there are empty columns to its right. This avoids clipping of long captions but still allows using multiple columns.
A node can be selected in every column (this is switchable) as well as edited, making Virtual Treeview some kind of a grid too. The tabulator key can be used to switch the focus between cells. A special option (toGridExtensions) exist to support grid specific tasks.
Nodes can have individual heights and the vertical alignment of a node's images and lines can be adjusted individually.
Virtual Treeview exposes its internal states like pending drag or edit events, multi selection or expanding in progress. Using this information an application can optimize its code execution (state updates etc.).
Sorting a node is supported via an application defined compare call back. Additionally, a tree can be set to auto sort.
Hints can contain multiple lines of text and mirror the alignment and directionality of the node or column they are displayed for. For their animation sliding and alpha blending is available.
Incremental search with various options and directions is available too.
Auto scrolling of the client area happens when the mouse is near the borders while dragging and draw selecting (multi selection).
TBaseVirtualTree.DefaultNodeHeight and TVirtualStringTree.DefaultText can be used to avoid setting many nodes explicitly to the same start value.
Virtual Treeview's column implementation also allows fixed columns, making it a good grid replacement too.
For smooth animations (e.g. hint fading) Virtual Treeview uses hand optimized MMX assembler routines. This code is also used to draw the translucent selection rectangle in multi selection mode. This is very much like what Windows 2000 and Windows XP support but works also on Windows 95/98/Me.
An alpha blended image of the tree window is shown while doing drag and drop. On Windows 2000 and Windows XP IDropTargetHelper and IDragSourceHelper interfaces are supported which allow for some very neat effects (as used by Explorer). On older consumer Windows versions the drag image is simulated by the tree but underlies there some minor limitations.
Virtual Treeview supports Windows XP themes. It acts properly on theme changes and uses for all visual elements which are themed the correct image by using native APIs. Under other Windows systems these styles are supported by separate legacy code. Theme awareness can be switched.
TVirtualStringTree is implemented using Unicode/wide strings exclusively.
The tree saves and reads all Unicode properties (e.g. column captions, default node text and the like) correctly to/from DFM.
All Unicode drawing fully supports bidirectionality (i.e. right-to-left drawing), column alignment (left, center, right) and correctly aligned hints. Of course also this feature is available on Windows 95/98/Me.
Drag'n drop and clipboard support
OLE drag and drop and OLE clipboard transfers are supported with the tree as source and target. Alternatively, VCL drag'n drop can still be used for compatibility.
These formats are support by the standard implementation:
Native serialized format (CF_VIRTUALTREE and CF_VTREFERENCE), which is a compact form to exchange data between Virtual Treeviews (also between applications). Two storage formats are available: HGlobal and IStream.
Plain ANSI text string format.
Plain Unicode text string format.
Rich Text (RTF) string format (with Unicode text).
HTML text string format (UTF-8). This is the preferred clipboard format for Word 2000 etc. and allows copy and paste tree content to a word document with nearly no application code.
There is a registration scheme (RegisterVTClipboardFormat) which allows descendants to specify and implement their own clipboard formats. Via a drop handler the application can accept any OLE format without deriving an own tree class. In order to aid processing of the native tree data specialized methods are implemented. See also: TBaseVirtualTree.ProcessOLEData and TBaseVirtualTree.ProcessDrop.
Dropmarks show during drag'n drop where data will be inserted. This works also with VCL drag'n drop. The drop target model has been extended to allow drop actions above, below or on a node. Meanwhile vendors of other treeview controls have started using this little but powerfull idea too.
Auto expand of nodes which are the drop target for more than an adjustable time interval is performed if enabled.
Header and columns
Multiple columns are supported by an own header implementation. This header takes up space in the non-client area of the tree control and supports various buttons styles (standard listview thick buttons, flat buttons, plates, Windows XP style and owner draw).
Columns can appear in every order in the tree window.
Each column can be hidden including the main column which holds the actual tree.
Each column can become the main column.
Columns can be shown also without the header.
Columns can have various options (visible, clickable, resizable, draggable etc.).
You can set individual alignments for each column as well as right-to-left or left-to-right directionality (again: available also on non-middle-east and older Windows consumer systems).
Each column can have an own color.
The header as well as the columns collection class and the actual column classes support streaming. This is independant from the treeview streaming.
Each node in the tree can have its own check type. This can either be check box (also tristate), radio button or node button. These types can freely be mixed so you can for instance have a node with 10 nodes of which 5 comprise a radio group (where only one of these 5 nodes can be checked) and the other 5 nodes can have a check box (or no check type at all).
Mixed (tri-state) check boxes with proper handling for partial checking of child nodes are supported (as often used in install and backup programs).
Automatic state change propagation for mixed check button type is possible (if enabled).
Check events OnChecking and OnCheck events are supplied too.
For special purposes a small flat button can be used, which is called a node button.
7 different kinds of check images are possible. Dark and light check marks, dark and light tick marks, flat check images, Windows XP style check images and application defined check images. For an overview see property TBaseVirtualTree.CheckImageKind.
Virtual Treeview's properties and methods are registered with Delphi categories (Delphi 5 and BCB 5 or higher).
A special property editor for the clipboard formats is included which allows a simple format choice. This is particularly important since the available clipboard formats must be given as strings and it is also quite handy to have a list of available formats, even if they are not enabled yet (to know what can be enabled).
Custom draw and paint cycles are supported via paint events (for the entire tree and for each node).
Apart from the built-in check types a user defined check image can be used which is supported by a separate image list (TBaseVirtualTree.CustomCheckImages).
Each button in the header can be drawn individually.
Three different lines styles are available: dotted lines, solid lines and application defined lines.
Applications and descendants can provide their own node editor (which has not necessarily to be a single control) by handling the TBaseVirtualTree.OnCreateEditor event or overriding TBaseVirtualTree.DoCreateEditor. This allows to completely replace node editing by own (business) rules.
Applications and descendants can provide their own drag manager interface by handling the TBaseVirtualTree.OnCreateDragManager event or overriding TBaseVirtualTree.DoCreateDragManager. This allows to customize the entire OLE drag handling of the tree. Note: VCL drag'n drop is managed by the VCL so this cannot be customized.
Applications and descendants can provide their own data object interface by handling the TBaseVirtualTree.OnCreateDataObject event or overriding TBaseVirtualTree.DoCreateDataObject. This allows to provide own clipboard formats.
There is a registration function (RegisterVTClipboardFormat), which allows to register tree descendants with own clipboard and/or storage formats. Applications can provide own clipboard formats (without deriving new tree classes) by handling the TBaseVirtualTree.GetUserClipboardFormats event.
Applications and descendants can completely modify the tree's key handling by handling the TBaseVirtualTree.OnKeyAction event or overriding TBaseVirtualTree.DoKeyAction. This works also for incremental search.
Applications and descendants can customize the tree's background which is not covered by nodes, by handling the TBaseVirtualTree.OnPaintbackground event or overriding TBaseVirtualTree.DoPaintbackground. For nodes there are further events for customization.
Applications and descendants can customize how the string tree shortens too long captions by handling the TCustomVirtualStringTree.OnShortenString event or overriding TCustomVirtualStringTree.DoShortenString.
Flat scroll bars are supported. but since they conflict with Windows XP this support is switched off by a compiler symbol (UseFlatScrollbars). Enable this symbol if you really want to use flat scroll bars before compiling the tree unit.
Every scroll operation triggers an TBaseVirtualTree.OnScroll event. This allows to synchronize trees with other controls.
There are properties (e.g. TBaseVirtualTree.OffsetXY) which allow to scroll the tree content to any postion in code without sending messages around.
Wheel panning and scrolling is supported. That is, when clicking the mouse wheel or pressing and holding it while moving the mouse around the tree window is scroll smoothly.
Sophisticated tree content serialization has been implemented to allow saving and restoring a tree to/from streams. This includes also user data as long as it can be written to a stream.
Virtual Treeview allows also to add data from stream instead replacing the entire content.
The internal format of the stream is chunk based which makes it very flexible for future enhancements but still keeps compatibility with older implementations.
There is a user chunk which takes data written to the stream in the TBaseVirtualTree.OnSaveNode event. The data of this user chunk is can be read in TBaseVirtualTree.OnLoadNode.
Special care has been taken to format the source code of Virtual Treeview consistently.
A large part of the entire implementation are comments which describe the inner workings.
Methods and properties are consequently ordered alphabetically within their scope (private, protected, public, published). The only exception are the constructors and destructors which always appear at the top of the public section in the class declaration and are always the first methods in the class implementation.
For every event there is a virtual method which calls the event handler. This allows descendants to get notice of every event without assigning a handler. The names of these methods correspond directly to the events by using the pattern: DoEventName.
Many measures have been taken to ensure borland C++ builder compatibility. This is particularly difficult because the automatic translation from Delphi to C++ code in BCB is buggy.
There is an easy and powerfull mechanism for descendants writers to allocate their own data on a per node basis. Simply call TBaseVirtualTree.AllocateInternalData to register your needs. This will not influence existing or future application code if it consequently uses TBaseVirtualTree.GetNodeData for user data access.
Application defined editors are supported via an edit link interface. A generic (non-Unicode) editor implementation is available too.
Every column in the tree is editable if enabled (see TCustomVirtualTreeOptions.SelectionOptions.toExtendedFocus).
For your convenience some of the internally used functions which are of general interest are exposed.
Alphablend: a general purpose procedure to blend a source onto a target bitmap using several different modes.
DrawTextW: a partial implementation of the DrawText API which supports Unicode. This method only has a stub on Windows 95/98/Me.
ShortenString: a general purpose function which makes a given WideString fitting into a given space. This is partially implemented by the Windows DrawText API but takes additionally care for right-to-left alignment and works with Unicode also on Windows 95/98/ME.
* Times given here are taken on a Windws XP professional system running on an Athlon 650 MHz with 256Mb RAM. All possible optimization were applied.
A collection of compiled demos showing various aspects of Virtual Treeview. The source for these demos are in the source code repository.
Note: these demos were compiled with an older version of VT. Use the source code to compile current binaries.