Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Deleting objects from collections (Read 3116 times)
MagnusSpeychal
Junior Member
**
Offline



Posts: 53
Joined: Jun 18th, 2007
Deleting objects from collections
Jul 19th, 2007 at 8:03am
Print Post  
Hi

I have loaded a file with the "LoadFromFile" method. The file was created using the "SaveToFile" method.
After loading the file I obtain a collection of boxes using the "GetBoxes"() method. I iterate over these boxes using the "GetCount" and "GetItem" methods. For certain conditions I wish to delete a box. I then use the "DeleteItem" method with a parameter obtained from the "GetItem" method. This gives me an error:
Unhandled exception... Access violation reading location...

Any ideas why this happens? I have used the "DeleteItem" method before without any problems. Is the problem related to loading the file or obtaining objects with the "GetItem" method?


Best regards,
Magnus
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Deleting objects from collections
Reply #1 - Jul 19th, 2007 at 10:30am
Print Post  
Hi,

Are you sure the exception is thrown by DeleteObject, and not by GetItem? Calling DeleteObject(box) removes the box from the Flowchart.Boxes collection, and that could lead to using a non-existing box index at some point in the loop.

Stoyan
  
Back to top
 
IP Logged
 
MagnusSpeychal
Junior Member
**
Offline



Posts: 53
Joined: Jun 18th, 2007
Re: Deleting objects from collections
Reply #2 - Jul 19th, 2007 at 11:59am
Print Post  
Hi Stoyan

Yes, the exception is thrown by DeleteObject. I suspected the GetItem method at first but it turned out that this is ok.
My code (for test purposes) looks something like this:

m_FlowChart.LoadFromFile(_T("test.sld"));
nodes=m_FlowChart.GetBoxes();
for(int i=0;i<nodes.GetCount();i++)
bi=nodes.GetItem(i);
m_FlowChart.DeleteItem(bi);

The exception is thrown on the first "round" in the loop.
After the GetItem method I use debugtools to check "bi" and all data seems correct.


Best regards,
Magnus

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Deleting objects from collections
Reply #3 - Jul 19th, 2007 at 3:49pm
Print Post  
Is that code invoked from a handler of some FlowchartX event?

Stoyan
  
Back to top
 
IP Logged
 
MagnusSpeychal
Junior Member
**
Offline



Posts: 53
Joined: Jun 18th, 2007
Re: Deleting objects from collections
Reply #4 - Jul 20th, 2007 at 3:57am
Print Post  
Hi Stoyan

I found the problem. Seems I am the one to blame since I did not see problem all the way through.
I have a lot of code in the "BoxDeleted" event which I did not handle correctly.
I am very sorry for taking your time with this and I hope you have not spent to much time on it.


Best regards,
Magnus
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint