davidberneda / GenericTree

Delphi implementation of a generic Tree structure
The Unlicense
59 stars 18 forks source link

TNodeDictionary (generic Tree dictionary) #2

Open davidberneda opened 9 years ago

davidberneda commented 9 years ago

It is currently possible to create a Tree of dictionary nodes, for example:

uses
   System.Generic.Collections;

type
  TMyTree = TNode<TDictionary<String, TButton>>;

In this way, each node "Data" property is a TDictionary that can be used as normal.

However, this is different than having a Tree structure where the children nodes are unique, and accessible using the desired "Key", for example.

type
  TMyTree = TNodeDictionary<String, Integer>;

var 
  Root : TMyTree;
...
  Root['America'].Data := 123;
  Root['America']['USA'].Data := 456;

In the above code, "USA" is a unique children node of "America", and each node has a "Data" property of type Integer.

edwinyzh commented 9 years ago

A nice idea idea, now it looks like a JSON object :smile:

Can we also do Root['America']['USA']['3rdLevel'].Data := 456; ?