TreeLoadFromXML procedure
Loads tree nodes stored in XML format to the specified tree view control.
Declaration
procedure TreeLoadFromXML(Tree: TCustomTreeView; const Fn: string;
Options: TTreeItemStorageOptions=TreeItemStorageDefaultOptions;
OnCallback: TTreeStorageCallback=Nil)Description
TreeLoadFromXMl is a an overloaded routine used to load the
hierarchical tree nodes stored in the Items property for the specified tree
view control from an XML storage format. The overloaded variants allow the XML
content to originate from either a file or a stream.
Tree is the
TCustomTreeView control where the tree nodes
are stored in the routine.
Options is a
TTreeItemStorageOptions set type which
controls the properties which are stored in TTreeNode instance which are read
from the XML storage format. The default value for the parameter is
TreeItemStorageDefaultOptions and causes all of the relevant properties for a
given tree node to be stored in the routine. See TTreeItemStorageOption for
information about Options values and their meanings.
Use the Fn or St arguments to specify the file name or
stream where the XML representation for the hierarchical tree structure was
stored.
OnCallback is an optional routine used to format / convert / cast arbitrary data in a tree node when it is read from DOM nodes in the specified XML file. OnCallback is called (when assigned) for each TTreeNode instance processed for the tree view control.
TreeLoadFromXML creates a TXMLDocument with the hierarchy of tree nodes found in the file or stream. The XML document contains elements with names like "Treeview", "Items", and "Node". For example:
<?xml version="1.0" encoding="UTF-8"?>
<Treeview>
<Items>
<Node Caption="Item0" Expanded="True">
<Node Caption="Item0_0"/>
<Node Caption="Item0_1"/>
</Node>
<Node Caption="Item1" Expanded="True">
<Node Caption="Item1_0"/>
<Node Caption="Item1_1"/>
</Node>
<Node Caption="Item2" Expanded="True">
<Node Caption="Item2_0" Expanded="True">
<Node Caption="Item2_0_0"/>
</Node>
</Node>
<Node Caption="Item3"/>
<Node Caption="Item foo bar"/>
</Items>
</Treeview>
TreeLoadFromXML updates the Items property in the tree view control. It clears the Items collection on entry, and adds a TTreeNode to Items for each of the Node elements in the XML content.
The Caption attribute for a Node element is stored as the Text for a given TTreeNode instance. Values in the Options argument control the other TTreeNode properties updated from the attribute values provided in Node elements. For example, when tsoExpanded has been included in Options the value for the Expanded attribute is stored in the Expanded property for the TTreeNode instance. When tsoVisible has been include in Option, the Visible attribute is used to set the value in the Visible property for the TTreeNode instance. Only those values specified in Options are applied to the TTreeNode instances created in the routine; other properties have their default values. Use the OnCallback routine to performs actions needed for untyped property values (like Data) or any tree node property not explicitly supported in Options.
See also
An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.
