Good evening, help me find a bug. The example parsed in Delphi http://decoding.dax.ru/practic/treeview/treeview.html is somehow translated into c ++ code, but does not work as it should. Either deletes all children because of node-> DeleteChildren (); , or displays the same directories of the root disk when you click on the disclosure of other folders.

AnsiString Dir = "D:"; TTreeNode *node; __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { node = TreeView1 -> Items -> AddChild(NULL,Dir); node -> HasChildren = true; } void __fastcall TForm1::NextLevel(TTreeNode *ParentNode) { TSearchRec sr; TSearchRec srChild; TTreeNode *node; AnsiString path; node = ParentNode; path = ""; do { path = node -> Text + "\\" + path; node = node -> Parent; } while (node != NULL); // Находим первую директорию if (FindFirst(path + "*.*", faAnyFile, sr) == 0 ) { do{ if ((sr.Name != "." ) && (sr.Name != ".." )) if (( sr.Attr && faAnyFile ) != 0) { // Добавляем найденную папку в TreeView node = TreeView1 -> Items -> AddChild(ParentNode, sr.Name); node -> SelectedIndex = 1; // Утверждаем, что нет подкаталогов node -> HasChildren = false; // Проверяем, так ли это if (FindFirst(path + sr.Name + "\*.*", faDirectory, srChild) == 0) { do { if ((srChild.Name != "." ) && ( srChild.Name != ".." )) if (( srChild.Attr && faAnyFile ) != 0) node -> HasChildren = true; } while ((FindNext(srChild) == 0 ) || (node -> HasChildren == false)); } FindClose(srChild); } } while (FindNext(sr) == 0); } else ParentNode -> HasChildren = false; FindClose(sr); } void __fastcall TForm1::TreeView1Expanding(TObject *Sender, TTreeNode *Node, bool &AllowExpansion) { TreeView1 ->Items->BeginUpdate(); node->DeleteChildren(); NextLevel(node); TreeView1 ->Items->EndUpdate(); } 

    0