Problem with TTreeView and AddChild


2007-06-05 04:55:45 AM
cppbuilder19
Hello all (i hope this is the right newsgroup...),
i've been scratching my head with the function below for days and would
appreciate some help. The objective of this function is to recursively look
through a directory and subdirectory for all folders that contain a
umfolder.ini file and add them to a Treeview control. That all works fine
but the function fails when the line to call Addchild is called.
The NewNode ptr is not initialised correctly and hence the remaining
assignments to NewNode fails. I know the searching etc works fine as i have
removed the TTreeview code and tested.
At the time the AddChild is called, the tNode, tv and asFolder variables are
all valid
void __fastcall TCC3UserFolders::GetUserContainerFolders(AnsiString
StartPath,TTreeView *tv,TTreeNode *tNode)
{
TSearchRec sr;
AnsiString asPath,asUMini,asFolder;
//TTreeNode *NewNode;
asPath = StartPath+"\\*.*";
if(FindFirst(asPath, 0x0000FFFF, sr) == 0)
{
do
{
if((sr.Attr & faDirectory)>0)
{
// sr.Name is a subdirectory
if((sr.Name!=".")&&(sr.Name!=".."))
{
asUMini=StartPath+"\\"+sr.Name+"\\UMFolder.ini";
if(FileExists(asUMini)) //Stops search going too deep
{
asFolder=sr.Name;
TTreeNode *NewNode =tv->Items->AddChild(tNode,asFolder); //@@LINE
DOES NOT WORK CORRECTLY
NewNode->ImageIndex =2;
NewNode->SelectedIndex =3;
NewNode->Data = new
AnsiString(StartPath+"\\"+sr.Name);
GetUserContainerFolders(StartPath+"\\"+sr.Name,tv,NewNode);
}
}
}
}
while(FindNext(sr) == 0);
FindClose(sr);
}
}
Can any bright spark spot anything obvious that i just cannot see??
All help appreciated
Thanks
Andy