I've been trying to make a copy and paste method for a treeview where if you copy it makes a clone of the tree ( a simple node->Clone() )
However, each node has a tag value that is a pointer to an attached structure. Since Object* doesn't have a public clone method I created one for each of the structures that returns this->MemberwiseClone(), and it works fine until the application is closed. Then I get this nice nasty error.
Currently this is the code I use to do the copying.
if(sn != NULL)
copyData = __try_cast<TreeNode*>(sn->Clone());
TreeNode* iter = copyData;
for(int i = 0; i < iter->Nodes->Count; i++){
iter = copyData->Nodes->Item;
iter->Tag = cloneLSF(iter->Tag);
for(int j = 0; j < iter->Nodes->Count; j++){
iter = copyData->Nodes->Item->Nodes->Item[j];
iter->Tag = cloneLSF(iter->Tag);
}
}
// note all objects inherit LSF_TYPE
System::Object* cloneLSF(System::Object* obj)
{
if(obj != NULL){
try{
return __try_cast<LSF_TYPE*>(obj)->Clone();
}
catch(System::Exception*){}
}
return NULL;
}
I've tried different ways of trying to clone them, but I get a similar error so I'm not quite sure what I'm doing wrong.
Thanks