Weird. Why can't I get TreeView to work all of a sudden? This was working the other day until I moved around some components on the form. This is a prototype data structure transformation tool. This is the code to produce a treeview to select the data category to process.
procedure TForm1.LoadCategoryTree(aCategories: tStringList);{ ---------------------------------------------------------------------------------------------------------------------------- FYI: TREE_Category : tTreeView on this form aCategories is input tStringlist with values as shown below OUTPUT Tree should look like: [] All Categories [] Classical\ [] General\ [] Oddities and Unfavorites\ [] Orbis Blues Collection\ [] Samplers\}var Category : string; RootNode : tTreeViewItem; ChildNode: tTreeViewItem; Childname: string; i : integer;begin me := 'LoadCategoryTree'; codesite.EnterMethod(self, me); CodeSite.Send(' ---- Construct Category Root Node ----- '); RootNode := tTreeViewItem.Create(self); RootNode.Text := 'All Categories'; RootNode.Name := 'CategoryRoot'; RootNode.Parent := TREE_Category; DEBUG_ReportRoot(RootNode); // debug CodeSite.Send(' ---- Construct Category Child Nodes ----- '); i := 0; for Category in aCategories do begin childname := 'CategoryNode_' + inttostr(i); ChildNode := tTreeViewItem.Create(self); ChildNode.Name := childname; ChildNode.Text := Category; ChildNode.Parent := RootNode; RootNode.EndUpdate; inc(i); DEBUG_ReportChild(ChildNode); // debug end; codesite.ExitMethod(self, me);end;procedure TForm1.DEBUG_ReportRoot(aRootNode: tTreeViewItem);{ ----------------------------------------------------------------------------------------------------------------------------}var myTree: TTreeView;begin myTree := TTreeView(aRootNode.Parent); codesite.Send('Root Parent Name', myTree.Name); // This should be 'TREE_Category' codesite.send('Root Name', aRootNode.Name); codesite.Send('Root Text', aRootNode.Text); codesite.Send('Root Children Count', aRootNode.ChildrenCount);end;procedure TForm1.DEBUG_ReportChild(aNewChild: tTreeViewItem);{ ----------------------------------------------------------------------------------------------------------------------------}var myChildParent: tTreeViewItem;begin myChildParent := tTreeViewItem(aNewChild.Parent); DEBUG_ReportRoot(myChildParent); codesite.Send('Child Parent Name', myChildParent.Name); codesite.Send('Child Parent Text', myChildParent.Text); codesite.Send('Sibling Count', myChildParent.ChildrenCount); codesite.Send('New Child Name', aNewChild.Name); codesite.Send('New Child Text', aNewChild.Text); codesite.AddSeparator;end; And here is the result: