Getting around vanishing pointers
-
Take for example the following code
CItemInfo *lp = new CItemInfo() lp->SetItemText("String"); CTreeItem *pParent = pList->InsertRootItem(lp); delete lp;
the following is for inserting data into a TreeList control. the problem here is that the command delete lp will delete the information stored in the treelist. If I change lp from heap to stack, I get the same result. If I remove delete lp then the information stays. Is there a way I can prevent this kind of occurance? I would like to clean up my pointers if possible but that seems to corrupt existing data. Thanks! -
Take for example the following code
CItemInfo *lp = new CItemInfo() lp->SetItemText("String"); CTreeItem *pParent = pList->InsertRootItem(lp); delete lp;
the following is for inserting data into a TreeList control. the problem here is that the command delete lp will delete the information stored in the treelist. If I change lp from heap to stack, I get the same result. If I remove delete lp then the information stays. Is there a way I can prevent this kind of occurance? I would like to clean up my pointers if possible but that seems to corrupt existing data. Thanks! -
Take for example the following code
CItemInfo *lp = new CItemInfo() lp->SetItemText("String"); CTreeItem *pParent = pList->InsertRootItem(lp); delete lp;
the following is for inserting data into a TreeList control. the problem here is that the command delete lp will delete the information stored in the treelist. If I change lp from heap to stack, I get the same result. If I remove delete lp then the information stays. Is there a way I can prevent this kind of occurance? I would like to clean up my pointers if possible but that seems to corrupt existing data. Thanks!See if your TreeList can associate an
LPARAM
with each item, like regular trees and lists do. If so, put the pointer in each item'sLPARAM
. Then when the items are removed from the control (TVN_DELETEITEM
for trees,LVN_DELETEITEM
for lists) delete the pointer then. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- I even hear the Windows "OMG I booted up fine" sound. -- Paul Watson diagnosing hardware problems. -
Take for example the following code
CItemInfo *lp = new CItemInfo() lp->SetItemText("String"); CTreeItem *pParent = pList->InsertRootItem(lp); delete lp;
the following is for inserting data into a TreeList control. the problem here is that the command delete lp will delete the information stored in the treelist. If I change lp from heap to stack, I get the same result. If I remove delete lp then the information stays. Is there a way I can prevent this kind of occurance? I would like to clean up my pointers if possible but that seems to corrupt existing data. Thanks!I guess there is not. The CTreeItem only stores the pointers you give him, not the actual data. So if you delete the data, the pointer the CTreeItem has is useless. Why don't you just delete them once you stop using the CTreeItem? (I have never worked with MFC etc, but this is a common practice)
-
Take for example the following code
CItemInfo *lp = new CItemInfo() lp->SetItemText("String"); CTreeItem *pParent = pList->InsertRootItem(lp); delete lp;
the following is for inserting data into a TreeList control. the problem here is that the command delete lp will delete the information stored in the treelist. If I change lp from heap to stack, I get the same result. If I remove delete lp then the information stays. Is there a way I can prevent this kind of occurance? I would like to clean up my pointers if possible but that seems to corrupt existing data. Thanks!