title: How to populate a tree view based on a flat list with "levels"?
body: <p>I have a list of objects populated from a third-party project file. The way this file was designed is so each item is on a "level" of hierarchy. So the very first item is on level 0, all of its child items are on level 1, and so on.</p>
  
  <p>As an example:</p>
  
  <pre><code>  1. Node 1     (Level 0)
    2. Node 1.1   (Level 1)
    3. Node 1.2   (Level 1)
    4. Node 1.3   (Level 1)
    5. Node 1.3.1 (Level 2)
    6. Node 1.4   (Level 1)
    7. Node 2     (Level 0)
    8. Node 2.1   (Level 1)
    9. Node 2.1.1 (Level 2)
   10. Node 3     (Level 0)
  </code></pre>
  
  <p>This would produce a hierarchy like so:</p>
  
  <pre><code>- Node 1
  --- Node 1.1
  --- Node 1.2
  --- Node 1.3
  ----- Node 1.3.1
  --- Node 1.4
  - Node 2
  --- Node 2.1
  ----- Node 2.1.1
  - Node 3
  </code></pre>
  
  <p>My issue is figuring out how to populate this structure into a VCL <code>TTreeView</code> based on these "Level" properties of each listed object. If I had designed this third-party file structure, I would have used a parent property instead of a level property.</p>
  
  <p>Objects in this list can be iterated like this:</p>
  
  <pre><code>var
    I: TMyItem;
    N: TTreeNode;
  begin
    for X := 0 to MyList.Count - 1 do begin
      I := MyList[X];
      //TMyItem has property "Level" which specifies hierarchy
      //  as well as "Title" property for the node's caption
      //How to create node based on Level?
  
      N.Data := I;
    end;  
  end;
  </code></pre>
  
  <p>Based on this structure, how do I populate this in a tree view?</p>