function TreeNodeChildCount(mTreeNode: TTreeNode): Integer;
var
  I: Integer;
begin
  Result := 0;
  if not Assigned(mTreeNode) then Exit;
  Result := mTreeNode.Count;
  for I := 0 to mTreeNode.Count - 1 do
    Result := Result + TreeNodeChildCount(mTreeNode[I]);
end; { TreeNodeChildCount }procedure TForm1.TreeView1GetSelectedIndex(Sender: TObject;
  Node: TTreeNode);
begin
  Caption := IntToStr(TreeNodeChildCount(TTreeView(Sender).Selected));
end;