--- ---

    function IsTreeviewFullyExpanded(tv: TTreeview): Boolean;
    var
      node: TTreenode;
    begin
      Assert(Assigned(tv));
      if tv.items.count > 0 then
      begin
        node := tv.Items[0];
        Result := true;
        while Result and Assigned(node) do
        begin
          Result := node.Expanded or not node.HasChildren;
          node := node.GetNext;
        end;
      end
      else
        Result := false
    end;

    function IsTreeviewFullyCollapsed(tv: TTreeview): Boolean;
    var
      node: TTreenode;
    begin
      Assert(Assigned(tv));
      if tv.items.count > 0 then
      begin
        node := tv.Items[0];
        Result := true;
        while Result and Assigned(node) do
        begin
          Result := not (node.Expanded and node.HasChildren);
          node := node.GetNext;
        end;
      end
      else
        Result := false
    end;