Skip to content

EF.Tree

Defines the tree and node class that implement a tree of named data values. A tree can represent a Yaml file or a JSON stream, for example.

TEFDataType class

Base class for node data types. The system supports pluggable data types. Descendants of this class define how to interpret, store, copy, encode and decode data of a particular type.

pascal
class function GetTypeName: string;

Returns the type's registration name (the class name stripped of the 'TEF' prefix and 'DataType' suffix).

pascal
class function HasSize: Boolean;

Returns True if this data type has a meaningful size (such as a string length).

pascal
class function HasScale: Boolean;

Returns True if this data type has a meaningful scale (number of decimal digits).

pascal
class function GetFieldType: TFieldType;

Returns the TFieldType that corresponds to this data type.

pascal
class function NeedsQuotes: Boolean;

Returns True if values of this type need to be quoted (for example in SQL or Yaml).

pascal
class procedure SetNodeDataTypeAndValueFromYaml(const AYamlValue: string;

Guesses a suitable data type from a Yaml value string and sets ANode's data type and value accordingly. When APreferStrings is True numbers are kept as strings.

pascal
procedure FieldValueToNode(const AField: TField;

Reads AField's value into ANode, setting the node to null when the field is null.

pascal
procedure NodeToField(const ANode: TEFNode;

Writes ANode's value into AField, clearing the field when the node is null.

pascal
procedure NodeToParam(const ANode: TEFNode;

Writes ANode's value into AParam, setting the param to null when the node is null.

pascal
procedure YamlValueToNode(const AYamlValue: string;

Parses a Yaml value string into ANode according to this data type.

pascal
function GetDefaultDisplayWidth(const ASize: Integer): Integer;

Returns the default display width, in characters, for a value of the given size.

pascal
function GetDefaultColumnAlignment: string;

Returns the default column alignment ('left', 'right', ...) for this data type.

pascal
function SupportsEmptyAsNull: Boolean;

Returns True if an empty value may be treated as null for this data type.

pascal
function GetDefaultEmptyAsNull: Boolean;

Returns the default EmptyAsNull setting for this data type.

pascal
function SupportsJSON: Boolean;

Returns True if values of this type can be represented in JSON.

pascal
function SupportsXML: Boolean;

Returns True if values of this type can be represented in XML.

pascal
function IsBlob(const ASize: Integer): Boolean;

Returns True if a value of the given size is stored as a BLOB.

pascal
function IsText: Boolean;

Returns True if this is a text data type.

pascal
function IsBoolean: Boolean;

Returns True if this is the boolean data type.

pascal
function NodeToJSONValue(const AForDisplay: Boolean;

Formats ANode's value as a JSON value, optionally quoted, returning 'null' (or '' if AEmptyNulls) for null nodes.

pascal
function NodeToXMLValue(const AForDisplay: Boolean;

Formats ANode's value as an XML element (<Name>value</Name>).

pascal
procedure JSONValueToNode(const ANode: TEFNode;

Parses a JSON value string into ANode, setting it to null for empty or 'null' input.

pascal
function GetJSTypeName: string;

Returns the JavaScript/ExtJS type name for this data type.

pascal
function ValueToString(const AValue: Variant): string;

Converts the stored variant value to a string.

pascal
function ValueToInteger(const AValue: Variant): Integer;

Converts the stored variant value to an Integer.

pascal
function ValueToObject(const AValue: Variant): TObject;

Converts the stored variant value to an object reference.

pascal
function ValueToBoolean(const AValue: Variant): Boolean;

Converts the stored variant value to a Boolean.

pascal
function ValueToStringArray(const AValue: Variant): TStringDynArray;

Converts the stored variant value to a string array.

pascal
function ValueToPairs(const AValue: Variant): TEFPairs;

Converts the stored variant value to a list of name/value pairs.

pascal
function ValueToDate(const AValue: Variant): TDate;

Converts the stored variant value to a Date.

pascal
function ValueToTime(const AValue: Variant): TTime;

Converts the stored variant value to a Time.

pascal
function ValueToDateTime(const AValue: Variant): TDateTime;

Converts the stored variant value to a DateTime.

pascal
function ValueToChar(const AValue: Variant): Char;

Converts the stored variant value to a Char.

pascal
function ValueToCurrency(const AValue: Variant): Currency;

Converts the stored variant value to a Currency.

pascal
function ValueToFloat(const AValue: Variant): Double;

Converts the stored variant value to a Double.

pascal
function ValueToDecimal(const AValue: Variant): TBcd;

Converts the stored variant value to a decimal (BCD).

pascal
function ValueToBytes(const AValue: Variant): TBytes;

Converts the stored variant value to a byte array.

pascal
function StringToValue(const AString: string): Variant;

Converts a string to this type's variant representation.

pascal
function IntegerToValue(const AInteger: Integer): Variant;

Converts an Integer to this type's variant representation.

pascal
function ObjectToValue(const AObject: TObject): Variant;

Converts an object reference to this type's variant representation.

pascal
function BooleanToValue(const ABoolean: Boolean): Variant;

Converts a Boolean to this type's variant representation.

pascal
function StringArrayToValue(const AStringArray: TStringDynArray): Variant;

Converts a string array to this type's variant representation.

pascal
function PairsToValue(const APairs: TEFPairs): Variant;

Converts a list of pairs to this type's variant representation.

pascal
function DateToValue(const ADate: TDate): Variant;

Converts a Date to this type's variant representation.

pascal
function TimeToValue(const ATime: TTime): Variant;

Converts a Time to this type's variant representation.

pascal
function DateTimeToValue(const ADateTime: TDateTime): Variant;

Converts a DateTime to this type's variant representation.

pascal
function CurrencyToValue(const ACurrency: Currency): Variant;

Converts a Currency to this type's variant representation.

pascal
function FloatToValue(const AFloat: Double): Variant;

Converts a Double to this type's variant representation.

pascal
function DecimalToValue(const ADecimal: TBcd): Variant;

Converts a decimal (BCD) to this type's variant representation.

pascal
function BytesToValue(const ABytes: TBytes): Variant;

Converts a byte array to this type's variant representation.

pascal
function CharToValue(const AChar: Char): Variant;

Converts a Char to this type's variant representation.

TEFStringDataType class

Data type for text values (Delphi strings).

pascal
class function GetFieldType: TFieldType;

Returns ftString.

pascal
function GetDefaultDisplayWidth(const ASize: Integer): Integer;

Returns the default display width for a string of the given size.

pascal
function SupportsEmptyAsNull: Boolean;

Returns True: empty strings may be treated as null.

pascal
function IsBlob(const ASize: Integer): Boolean;

Returns False: a plain string is not a BLOB.

pascal
function GetJSTypeName: string;

Returns the JavaScript type name for strings.

pascal
class function HasSize: Boolean;

Returns True: strings have a size (length).

pascal
function IsText: Boolean;

Returns True: this is a text data type.

pascal
function GetDefaultEmptyAsNull: Boolean;

Returns the default EmptyAsNull setting for strings.

TEFMemoDataType class

Data type for long text (memo) values.

pascal
function IsBlob(const ASize: Integer): Boolean;

Returns True when the size marks the value as a BLOB-sized memo.

pascal
class function HasSize: Boolean;

Returns False: memo values have no fixed size.

TEFBlobDataType class

Data type for binary (BLOB) values.

pascal
class function GetFieldType: TFieldType;

Returns ftBlob.

pascal
function IsBlob(const ASize: Integer): Boolean;

Returns True: this is always a BLOB.

pascal
function SupportsJSON: Boolean;

Returns False: BLOBs are not represented in JSON.

TEFDateTimeDataTypeBase class

Common base for the Date, Time and DateTime data types.

pascal
function GetDefaultEmptyAsNull: Boolean;

Returns the default EmptyAsNull setting for date/time types.

TEFDateDataType class

Data type for date-only values.

pascal
class function GetFieldType: TFieldType;

Returns ftDate.

pascal
function GetDefaultDisplayWidth(const ASize: Integer): Integer;

Returns the default display width for a date value.

pascal
function SupportsEmptyAsNull: Boolean;

Returns True: empty dates may be treated as null.

pascal
function InternalFormatNodeValue(const AForDisplay: Boolean;

Formats the node's date value, using ISO format when not for display.

pascal
function GetJSTypeName: string;

Returns the JavaScript type name for dates.

pascal
function ValueToString(const AValue: Variant): string;

Converts the stored date value to a string.

TEFTimeDataType class

Data type for time-only values.

pascal
class function GetFieldType: TFieldType;

Returns ftTime.

pascal
function GetDefaultDisplayWidth(const ASize: Integer): Integer;

Returns the default display width for a time value.

pascal
function SupportsEmptyAsNull: Boolean;

Returns True: empty times may be treated as null.

pascal
function InternalFormatNodeValue(const AForDisplay: Boolean;

Formats the node's time value, using ISO format when not for display.

pascal
function ValueToString(const AValue: Variant): string;

Converts the stored time value to a string.

TEFDateTimeDataType class

Data type for combined date and time values.

pascal
class function GetFieldType: TFieldType;

Returns ftDateTime.

pascal
function GetDefaultDisplayWidth(const ASize: Integer): Integer;

Returns the default display width for a date/time value.

pascal
function SupportsEmptyAsNull: Boolean;

Returns True: empty date/times may be treated as null.

pascal
function InternalFormatNodeValue(const AForDisplay: Boolean;

Formats the node's date/time value, using ISO format when not for display.

pascal
function GetJSTypeName: string;

Returns the JavaScript type name for date/times.

pascal
function ValueToString(const AValue: Variant): string;

Converts the stored date/time value to a string.

TEFBooleanDataType class

Data type for boolean values.

pascal
class function NeedsQuotes: Boolean;

Returns False: boolean values are not quoted.

pascal
class function GetFieldType: TFieldType;

Returns ftBoolean.

pascal
function GetDefaultDisplayWidth(const ASize: Integer): Integer;

Returns the default display width for a boolean value.

pascal
function InternalFormatNodeValue(const AForDisplay: Boolean;

Formats the node's boolean value as a string.

pascal
function GetJSTypeName: string;

Returns the JavaScript type name for booleans.

pascal
function IsBoolean: Boolean;

Returns True: this is the boolean data type.

TEFNumericDataTypeBase class

Common base for the numeric data types (Integer, Float, Currency, Decimal).

pascal
class function NeedsQuotes: Boolean;

Returns False: numeric values are not quoted.

TEFIntegerDataType class

Data type for integer values.

pascal
class function GetFieldType: TFieldType;

Returns ftInteger.

pascal
function GetDefaultColumnAlignment: string;

Returns 'right': integers are right-aligned.

pascal
function GetDefaultDisplayWidth(const ASize: Integer): Integer;

Returns the default display width for an integer value.

pascal
function GetJSTypeName: string;

Returns the JavaScript type name for integers.

TEFDecimalNumericDataTypeBase class

Common base for the decimal numeric data types (Currency, Float, Decimal).

TEFCurrencyDataType class

Data type for currency (monetary) values.

pascal
class function GetFieldType: TFieldType;

Returns ftCurrency.

pascal
function GetDefaultColumnAlignment: string;

Returns 'right': currency values are right-aligned.

pascal
function GetDefaultDisplayWidth(const ASize: Integer): Integer;

Returns the default display width for a currency value.

pascal
function SupportsEmptyAsNull: Boolean;

Returns True: empty currency values may be treated as null.

pascal
function InternalFormatNodeValue(const AForDisplay: Boolean;

Formats the node's currency value as a string.

pascal
function GetJSTypeName: string;

Returns the JavaScript type name for currency values.

pascal
class function HasSize: Boolean;

Returns True: currency values have a size.

pascal
class function HasScale: Boolean;

Returns True: currency values have a scale.

TEFFloatDataType class

Data type for floating-point values.

pascal
class function GetFieldType: TFieldType;

Returns ftFloat.

pascal
function GetDefaultColumnAlignment: string;

Returns 'right': float values are right-aligned.

pascal
function GetDefaultDisplayWidth(const ASize: Integer): Integer;

Returns the default display width for a float value.

pascal
function SupportsEmptyAsNull: Boolean;

Returns True: empty float values may be treated as null.

pascal
function InternalFormatNodeValue(const AForDisplay: Boolean;

Formats the node's float value as a string.

pascal
function GetJSTypeName: string;

Returns the JavaScript type name for float values.

TEFDecimalDataType class

Data type for high-precision decimal (BCD) values.

pascal
class function GetFieldType: TFieldType;

Returns ftFMTBcd.

pascal
function GetDefaultColumnAlignment: string;

Returns 'right': decimal values are right-aligned.

pascal
function GetDefaultDisplayWidth(const ASize: Integer): Integer;

Returns the default display width for a decimal value.

pascal
function SupportsEmptyAsNull: Boolean;

Returns True: empty decimal values may be treated as null.

pascal
function InternalFormatNodeValue(const AForDisplay: Boolean;

Formats the node's decimal value as a string.

pascal
function GetJSTypeName: string;

Returns the JavaScript type name for decimal values.

pascal
class function HasSize: Boolean;

Returns True: decimal values have a size.

pascal
class function HasScale: Boolean;

Returns True: decimal values have a scale.

TEFObjectDataType class

Stores the address of an object. This is only used for in-memory transfers, it is not persistable.

pascal
function GetDefaultDisplayWidth(const ASize: Integer): Integer;

Returns the default display width for an object reference value.

TEFTree class

The root of a tree. Contains a set of nodes which are in turn trees.

TComparer class

TEFPersistentTree class

A tree that stores a file name (or other logical identifier).

pascal
procedure AfterLoad;

Called after the tree is loaded from its persistent store; triggers post-load processing.

pascal
procedure Assign(const ASource: TEFTree;

Makes this tree a copy of ASource, also copying the persistent name.

pascal
property PersistentName: string read FPersistentName write FPersistentName;

Logical identifier (usually the file name without path/extension) of the persistent tree.

pascal
property IsPersistent: Boolean read GetIsPersistent;

Returns True if the tree has a persistent name.

pascal
property PersistentFileName: string read GetPersistentFileName;

Returns the full path name of the persistent file.

TEFNode class

A node in a tree. Has a name and a value, and can have subnodes.

pascal
function GetEnumerator: TEnumerator<TEFNode>;

Returns an enumerator over the node's direct children (enables for-in loops).

pascal
function GetEmptyAsNull: Boolean;

Returns whether an empty value should be treated as null, per the node's data type.

pascal
function GetRoot: TEFTree;

Returns the root of the tree, walking up through the parent nodes.

pascal
function FindNode(const APath: string;

Finds a node by path relative to this node; an empty path returns the node itself.

pascal
procedure Assign(const ASource: TEFTree;

Copies everything from ASource, overwriting any existing data. if ASource is a node, name and value are copied as well.

pascal
procedure AssignValue(const ASource: TEFNode);

Copies the value (and datatype) from the specified node. The name is unchanged.

pascal
property Parent: TEFTree read FParent;

A reference to the parent node, if any.

pascal
property Index: Integer read GetIndex;

Index of the node in the parent's list of node.

-1 if the node has no parent.

pascal
constructor Create(const AName: string;

Creates a node with specified name and value.

pascal
constructor Create(const AName: string);

Creates a node with specified name and no value.

pascal
constructor Create;

Creates a node with no name and no value.

pascal
constructor Clone(const ASource: TEFTree;

Creates a new node and assigns the specified node to it.

pascal
procedure Clear;

Deletes all subnodes, recursively.

pascal
procedure Delete;

Removes itself from its parent. This causes the parent to free the current object.

pascal
property Name: string read GetName write SetName;

Identifies the node among its siblings. Should be unique inside the parent.

pascal
procedure Rename(const ANewName: string);

Renames the node. Normally shouldn't be used.

pascal
property DataType: TEFDataType read GetDataType write SetDataType;

A reference to the node's data type. Should be an object managed by the data type factory.

pascal
function LockDataType: Integer;

Increments and returns the DataType lock count. When the number is > 0, assigning a value through the As... properties will not change the datatype (unless it's unknown). This also applies to any other operation that implicitly changes the DataType. Explicitly setting DataType is still allowed even when locked.

pascal
function UnlockDataType: Integer;

Decrements and returns the DataType lock count. This call does not guarantee that the DataType will be unlocked. It will only when the returned value is zero, which happens when calls to LockDataType and UnlockDataType are balanced. LockDataType

pascal
property Value: Variant read GetValue write SetValue;

Plain value of the node.

pascal
property ValueAttributes: string read FValueAttributes write FValueAttributes;

Used for I/O.

pascal
property IsMultiLineValue: Boolean read GetIsMultiLineValue;

True if the value spans multiple lines or is flagged as folded ('>') in its value attributes.

pascal
property IsMultiLineWithNLValue: Boolean read GetIsMultiLineWithNLValue;

True if the value contains explicit line breaks or is flagged as literal ('|') in its value attributes.

pascal
property AsString: string read GetAsString write SetAsString;

Node value as a string.

pascal
property AsChar: Char read GetAsChar write SetAsChar;

Node value as a string.

pascal
property AsStringArray: TStringDynArray read GetAsStringArray write SetAsStringArray;

Node value as a string array.

pascal
property AsPair: TEFPair read GetAsPair write SetAsPair;

Node value as a pair.

pascal
property AsExpandedPair: TEFPair read GetAsExpandedPair;

Node value as a pair with expanded macros in the value part.

pascal
property AsPairs: TEFPairs read GetAsPairs write SetAsPairs;

Node value as a list of pairs.

pascal
property AsExpandedString: string read GetAsExpandedString;

Node value as an expanded string.

pascal
property AsInteger: Integer read GetAsInteger write SetAsInteger;

Node value as an Integer.

pascal
property AsObject: TObject read GetAsObject write SetAsObject;

Node value as an object.

pascal
property AsBoolean: Boolean read GetAsBoolean write SetAsBoolean;

Node value as a Boolean.

pascal
property AsDate: TDate read GetAsDate write SetAsDate;

Node value as a Date.

pascal
property AsTime: TTime read GetAsTime write SetAsTime;

Node value as a Time.

pascal
property AsDateTime: TDateTime read GetAsDateTime write SetAsDateTime;

Node value as a DateTime.

pascal
property AsCurrency: Currency read GetAsCurrency write SetAsCurrency;

Node value as a Currency.

pascal
property AsFloat: Double read GetAsFloat write SetAsFloat;

Node value as a Double floating point value.

pascal
property AsDecimal: TBcd read GetAsDecimal write SetAsDecimal;

Node value as a decimal (BCD) value.

pascal
property AsBytes: TBytes read GetAsBytes write SetAsBytes;

Node value as a byte array.

pascal
procedure LoadBytesFromStream(const AStream: TStream);

Loads the whole content of AStream into the node's value as a byte array.

pascal
function SetAsYamlValue(const AValue: string;

Parses AValue trying to guess its data type and sets Value and DataType accordingly.

Parameters:

  • AValue — Value to parse, usually read from a Yaml stream.
  • AFormatSettings — Format settings to use to parse the value. You can use Session.UserFormatSettings, or Session.JSFormatSettings, or custom settings.

Returns: Returns Self to allow for fluent calls.

pascal
function SetAsJSONValue(const AValue: string;

Parses AValue according to DataType and sets its own value to the parsed value.

Parameters:

  • AValue — Value to parse, usually got from a web request.
  • AUseJSDateFormat — Set to True if date/times are specified in JS long format.
  • AFormatSettings — Format settings to use to parse the value. You can use Session.UserFormatSettings, or Session.JSFormatSettings, or custom settings.

Returns: Returns Self to allow for fluent calls.

pascal
property IsNull: Boolean read GetIsNull;

True if the node is null. Null is meant as absence of a value. Nodes are made null by calling their SetToNull method.

pascal
procedure SetToNull(const AForceChangeNotification: Boolean = False);

Sets the node to null, effectively clearing the value.

Children are unaffected.

pascal
function EqualsNode(const ANode: TEFNode): Boolean;

Returns true if the current node has the same name and value as the specified node, or if both are null.

Children are not considered.

pascal
function EqualsValue(const AValue: Variant): Boolean;

Returns True if the current node has specified value or if both the node and the value are null.

Children are not considered.

pascal
function GetChildStrings(const ASeparator: string = sLineBreak;

Returns all child nodes as a string of name<AConnector>value pairs separated by ASeparator.

pascal
function GetChildStrings(const AStrings: TStrings): Integer;

Adds to the specified string list all child nodes as strings in the form Name=Value. Returns the number of added items. All existing contents in AStrings are deleted.

pascal
function GetChildValues(const AStrings: TStrings): Integer;

Adds to the specified string list all child node values. Returns the number of added items. All existing contents in AStrings are deleted.

pascal
function GetChildNames(const AStrings: TStrings): Integer;

Adds to the specified string list all child node names. Returns the number of added items. All existing contents in AStrings are deleted.

pascal
procedure SetChildStrings(const AStrings: TStrings);

Deletes all children and adds a new children for each string in the specified string list. Strings must be in the form Name=Value. All existing contents in AStrings are deleted.

pascal
function GetExpandedChildStrings(const ASeparator, AConnector, ADefaultValue: string): string;

Returns all child nodes as a string of name<AConnector>value pairs separated by ASeparator. Values are expanded.

pascal
function GetChildPairs(const AExpandMacrosInValues: Boolean = False): TEFPairs;

Returns all child nodes as name/value pairs.

pascal
function GetChildNames: TStringDynArray;

Returns an array of names of all direct children of the node.

pascal
function ToArray: TArray<TEFNode>;

Returns an array of references to all direct children of the node.

pascal
procedure AssignFieldValue(const AField: TField);

Assigns a field's value to the node. May also change or set the node's datatype.

pascal
procedure AssignValueToField(const AField: TField);

Assigns the node's value to the specified field.

pascal
procedure AssignValueToParam(const AParam: TParam);

Assigns the node's value to the specified param. May also set the param's data type.

pascal
procedure AssignToParam(const AParam: TParam);

Assigns the node's name and value to the specified param. May also set the param's data type.

pascal
function GetPath: string;

Returns the node's slash-separated path, up to the root.

TEFTreeFactory class

Creates trees of specified types from files.

pascal
class function LoadFromFile<T: TEFTree, constructor>(const AFileName: string): T;

Loads the specified yaml file and builds a tree of the specified type with all data in it.

pascal
class procedure ReloadFromFile(const ATree: TEFTree;

Reloads the specified yaml file into an existing tree, overwriting any data in it.

TEFTreeMacroExpander class

A macro expander that expands all the strings contained in a TEFTree object. Each macro in this format:

%<NameSpace>:<Path>%

is expanded to the string value of the tree node located by the path. This macro expander holds a reference to a TEFTree. <NameSpace> is a value set upon creation. If it is empty, then no ':' separator is required in the macros.

The need for a name space stems from the fact that you can have multiple macro expanders of this kind active at the same time, each linked to a differentàtree object, and use the namespace string to differentiate them.

This macro expander is not registered by default, as it needs a reference to an external object to work. So, applications will create and use this class autonomously (by querying it directly or adding it to an expansion engine, without registering it) as required.

pascal
constructor Create(const ATree: TEFTree;

Creates the expander bound to ATree, using ANameSpace as the macro name space prefix.

TEFDataTypeRegistry class

Keeps track of all registered data types.

pascal
function GetClass(const AId: string): TEFDataTypeClass;

Returns the registered data type class with the given Id.

pascal
property Classes;

The registered classes, so the factory can instantiate them all up front and keep its dictionary read-only while requests are served.

TEFDataTypeFactory class

Holds a list of registered data types and manages their lifetimes.

pascal
procedure PreloadRegisteredTypes;

Instantiates every registered data type, so that the dictionary is complete before any request is served and GetDataType becomes a plain read. Called once at unit initialization: this is a singleton shared by every thread, on a path taken by each and every value assignment, so filling it lazily meant two concurrent first uses of the same type could both add it (EListError) or read it during a rehash.

pascal
class destructor Destroy;

Frees the singleton instance at unit finalization.

pascal
procedure AfterConstruction;

Creates the internal dictionary of instantiated data types.

pascal
destructor Destroy;

Frees all instantiated data types and the factory.

pascal
function GetDataType(const AId: string): TEFDataType;

Returns a reference to the registered data type specified by name.

pascal
function GetDataType(const ADataTypeClass: TEFDataTypeClass): TEFDataType;

Returns a reference to the registered data type specified by class.

Routines

pascal
constructor Create;

Creates an empty tree.

pascal
destructor Destroy;

Destroys the tree and all its nodes.

pascal
procedure BeforeSave;

Called before the tree is saved; recursively notifies all children.

pascal
function QueryInterface(const IID: TGUID;

IInterface support: queries for a supported interface.

pascal
function _AddRef: Integer;

IInterface support: no-op reference count increment (lifetime is not managed by refcounting).

pascal
function _Release: Integer;

IInterface support: no-op reference count decrement (lifetime is not managed by refcounting).

pascal
constructor Clone(const ASource: TEFTree;

Creates a new tree holding a deep copy of the specified tree.

pascal
function GetRoot: TEFTree;

Returns the root of the tree. In this class, returns Self.

pascal
procedure Clear;

Clears the tree, recursively deleting all nodes.

pascal
procedure Assign(const ASource: TEFTree;

Makes the current object a copy of the specified tree.

pascal
procedure Merge(const ASource: TEFTree);

Adds all nodes in ASource, overwriting any existing nodes with the same name. Note: does not copy annotations.

pascal
function AddChild(const ANode: TEFNode): TEFNode;

Adds a child node. Returns a reference to the added object.

pascal
function AddChild(const AName: string;

Creates a child node of a type that may depend on the parameters, fills and adds it. Then returns a reference to the added object.

pascal
function AddChild(const AName: string): TEFNode;

Creates a child node of a type that may depend on the parameters, sets the name and adds it. Then returns a reference to the added object.

pascal
function FindChild(const AName: string;

Finds a child node by name. Returns nil if not found.

Parameters:

  • AName — Name of the child node to look for.
  • ACreateMissingNode — Creates the node if not found.
  • ARecursively — If true, searches also in child nodes recursively
pascal
function FindChildByNameAndValue(const AName: string;

Finds a child node with specified name and value and returns a reference to it, or nil if the node is not found.

Parameters:

  • AName — Name of the child node to look for.
  • AValue — Value of the child node to look for.
  • ARecursively — If true, searches also in child nodes recursively
pascal
function FindChildByValue(const AValue: Variant;

Finds a child node with specified value and returns a reference to it, or nil if the node is not found.

Parameters:

  • AValue — Value of the child node to look for.
  • ARecursively — If true, searches also in child nodes recursively
pascal
function HasChild(const AName: string;

Returns True if a child with the given name exists, and False otherwise.

pascal
function HasChild(const AChild: TEFNode;

Returns True if the specified child exists, and False otherwise.

pascal
function FindChildByPredicate(const APredicate: TNodePredicate;

Finds a child node by predicate. The predicate function is called for each child and should return True if a child qualifies. The method returns the first qualifying child (and stops as soon as it is found). If no qualifying child is found, the method return nil.

Parameters:

  • APredicate — Function for testing purpose
  • ARecursively — If true, searches also in child nodes recursively
pascal
procedure EnumChildren(const AProc: TNodeProc;

Calls APredicate for each direct child node. If APredicate returns True, calls AProc passing the qualifying child node.

pascal
function ChildByName(const AName: string): TEFNode;

Finds a child node by name. Raises an exception if not found.

pascal
procedure RemoveChild(const ANode: TEFNode);

Removes the child from the list of children, if present.

pascal
procedure ClearChildren;

Removes all children, recursively.

pascal
function GetChildCount<T: class>: Integer;

Returns the count of direct children of a specified type.

pascal
function GetChild<T: class>(const AIndex: Integer): T;

Indexed access to a list of children limited to the set of children that are of the specified type.

pascal
function GetChildIndex<T: class>(const AChild: T): Integer;

Returns the index of a given child node in a list of children limited to the set of children that are of the specified type, or -1 if the specified children is not a direct child of the current tree.

pascal
function FindNode(const APath: string;

Searches a node by a path. Separate hierarchy elements with a /.

Parameters:

  • APath — A string path. Example: Node/SubNode.
  • ACreateMissingNodes — If True, creates any missing nodes throughout the path and the final node as well. This guarantees that the result is not nil.

Returns: The found node, or nil.

pascal
function FindNode(const APaths: TStringDynArray): TEFNode;

Searches a node by trying a sequence of paths in given order.

Parameters:

  • APaths — A sequence of string paths to try. Example: ['Node/SubNode', 'Node/SubNode2'].

Returns: The first node found, or nil.

pascal
function GetNode(const APath: string;

Works like FindNode, but raises an exception if ACreateMissingNodes is False and the wanted node does not exist.

Parameters:

  • ACreateMissingNodes — If True, creates any missing nodes throughout the path and the final node as well. This guarantees that the result is not nil.

Returns: The found node.

pascal
procedure DeleteNode(const APath: string);

Finds a node by path and, if found, deletes it.

pascal
function GetValue(const APath: string;

Finds a node by path and, if found, returns its value, otherwise returns ADefaultValue.

pascal
function GetValue(const APath: string): Variant;

Finds a node by path and, if found, returns its value, otherwise returns Null.

pascal
function GetBoolean(const APath: string;

Finds a node by path and, if found, returns its value as a Boolean, otherwise returns ADefaultValue.

pascal
function GetFloat(const APath: string;

Finds a node by path and, if found, returns its value as a Double, otherwise returns ADefaultValue.

pascal
function GetInteger(const APath: string;

Finds a node by path and, if found, returns its value as an Integer, otherwise returns ADefaultValue.

pascal
function GetString(const APath: string;

Finds a node by path and, if found, returns its value as a string, otherwise returns ADefaultValue.

pascal
function GetChar(const APath: string;

Finds a node by path and, if found, returns its value as a char, otherwise returns ADefaultValue.

pascal
function GetDate(const APath: string;

Finds a node by path and, if found, returns its value as a Date, otherwise returns ADefaultValue.

pascal
function GetExpandedString(const APath: string;

Finds a node by path and, if found, returns its value as an expanded string, otherwise returns ADefaultValue.

<returns> The found node's string with any macros expanded. <returns>

If the node is not found, macros in ADefaultValues are expanded as well before returning it. This method guarantees that the return value has all known macros expanded anyway.

pascal
function GetStringArray(const APath: string;

Finds a node by path and, if found, returns its value as a string array, otherwise returns ADefaultValue.

pascal
function GetPairs(const APath: string;

Finds a node by path and, if found, returns its value as a list of pairs, otherwise returns ADefaultValue.

pascal
function GetChildrenAsStrings(const APath: string;

Returns a separated list of all children of the specified node in the form Name<AConnector>AsString.

Parameters:

  • APath — Locates the parent node of the strings to extract.
  • ASeparator — Separator for name/value pairs (ex. '=').
  • AConnector — String used to connect pairs (ex. sLineBreak).
  • ADefaultValue — Value to return when the node does not exist.

Returns: A concatenation of all children of the specified node built according to the arguments.

pascal
function GetChildrenAsStrings(const APath: string;

Returns a list of all children of the specified node in the form Name=AsString.

Parameters:

  • APath — Locates the parent node of the strings to extract.
  • AStrings — Object to which strings are to be added. Any exiting contents are deleted.

Returns: The number of appended items.

pascal
procedure SetChildrenAsStrings(const APath: string;

Deletes all children nodes and replaces them with one node for each item in the specified string list. Strings must be in the form Name=Value.

pascal
function GetChildrenAsPairs(const APath: string;

Returns an array of all children of the specified node, which must be in name=value format, as pairs.

Parameters:

  • APath — Locates the parent node of the strings to extract.

Returns: Array of name/value pairs.

pascal
function GetChildrenAsExpandedStrings(const APath: string;

Same as GetChildrenAsStrings, but returns expanded strings: Each string is passed to the macro expander before concatenation.

pascal
function GetObject(const APath: string;

Finds a node by path and, if found, returns its value as an object, otherwise returns ADefaultValue.

pascal
function GetObject<T: class>(const APath: string): T;

Finds a node by path and returns its object value cast to T, or nil if not found.

pascal
procedure SetInteger(const APath: string;

Sets a node value by path. The node is created if it doesn't exist yet.

pascal
function SetString(const APath: string;

Sets a node value by path. The node is created if it doesn't exist yet.

pascal
function SetFloat(const APath: string;

Sets a node value by path. The node is created if it doesn't exist yet.

pascal
function SetValue(const APath: string;

Sets a node value by path. The node is created if it doesn't exist yet.

pascal
procedure SetObject(const APath: string;

Sets a node value by path. The node is created if it doesn't exist yet.

pascal
procedure SetBoolean(const APath: string;

Sets a node value by path. The node is created if it doesn't exist yet.

pascal
procedure SetDateTime(const APath: string;

Sets a node value by path. The node is created if it doesn't exist yet.

pascal
procedure AddFieldsAsChildren(const AFields: TFields);

Creates a children for each field in AField and sets its value to the field's value. Node names are field names. Existing nodes are overwritten.

pascal
function AddAnnotation(const AAnnotation: string): Integer;

Adds an annotation string and returns its index.

pascal
procedure AssignAnnotations(const AStrings: TStrings);

Replaces the tree's annotations with the contents of AStrings.

pascal
function GetPath: string;

Returns a string-based path. Returns '' in the tree, and a slash-separated path in the nodes.

pascal
procedure Sort(const ACompareFunc: TEFNodeCompareFunc);

Sorts the direct child nodes using the given comparison function.

pascal
procedure SetPropertyFromNode(const AInstance: TObject;

Looks for the node specified by APath and, if found, sets the same-named property of AInstance to the node's value. If APath is a compound path (such as Path/To/Property) then only the last part is used. If ApathIsName is True, then the path is assumed not to be compound and the code is more efficient.

pascal
procedure SetPropertiesFromNode(const AInstance: TObject;

Same as SetPropertyFromNode but for an array of nodes/properties.

pascal
procedure SetPropertiesFromChildNodes(const AInstance: TObject);

Calls SetPropertyFromNode for all direct children. If any children don't have corresponding properties, then an exception is raised.

pascal
procedure CopyChildValues(const ASource: TEFTree;

Tries to read from ASource a value for each child node, interpreting it according to the child node's DataType. Read values are stored in the child nodes.

Parameters:

  • ASource — Source data. Only top-level nodes are copied. Each node may contain a single value. If AValueIndex is >= 0, each node may contain one or more comma-separated string values, of which only the one with index AValueIndex is read.
  • AUseJSDateFormat — True if any dates in source strings are in JS format; False for system format.
  • AFormatSettings — Custom format settings to decode values.
  • ATranslator — Pass a translation function if key names in ASource do not match wanted child node names and you need to translate them. The function receives the child name and should return the corresponding source name.

Released under Apache License, Version 2.0.