Report Control crash when deleting items |
Post Reply |
Author | |
JemeraldSoft
Newbie Joined: 18 October 2006 Status: Offline Points: 3 |
Post Options
Thanks(0)
Posted: 18 October 2006 at 8:55am |
Hi, I just started using the report control in the toolkit in my application but found some issues with it.
My application has some background thread that dynamically add/delete entries to/from the report control. However, sometimes the control crashes when items are deleted. Deletion are done using (index is a valid index): m_lstAlarm.GetRecords()->RemoveAt(index); If I run it in the debug mode, I can see that the crashing happens in one of the following places: 1. drawing routine 2. tooltip routine 3. on mouse move seems like it''s trying to access the deleted record. Did I do something wrong. |
|
rmercer
Groupie Joined: 22 February 2006 Status: Offline Points: 34 |
Post Options
Thanks(0)
|
Did you call Populate() after you removed the record?
m_lstAlarm.GetRecords()->RemoveAt(index);
m_lstAlarm.Populate(); |
|
JemeraldSoft
Newbie Joined: 18 October 2006 Status: Offline Points: 3 |
Post Options
Thanks(0)
|
Yes I do, is the following code right? or do I need to call Populate() after every RemoveAt():
// delete the alarms associated with the disconnected server for(int i = 0; i < m_lstAlarm.GetRecords()->GetCount();) { CAlarmRecord * pRecord = (CAlarmRecord*)m_lstAlarm.GetRecords()->GetAt(i); if(pRecord && pRecord->m_iHostId == pHost->m_hostId) { m_lstAlarm.GetRecords()->RemoveAt(i); } else i++; } m_lstAlarm.Populate(); |
|
JemeraldSoft
Newbie Joined: 18 October 2006 Status: Offline Points: 3 |
Post Options
Thanks(0)
|
I also tried delete the row before deleting the record:
m_lstAlarm.GetRows()->RemoveAt(i); |
|
rmercer
Groupie Joined: 22 February 2006 Status: Offline Points: 34 |
Post Options
Thanks(0)
|
I don't see anything wrong with your code, however I just noticed that you mentioned this is running in a seperate thread. I would guess that's where your issue is at.
I've ran into this in the past where a thread removes records while the window thread is trying to process messages and is getting data that no longer exists.
You will probably need to do your removes using a custom windows message or figure out a way to lock the control from updating while you're making your changes.
To test the idea, can you just setup a WM_TIMER handler to run the code your thread would normally execute? Just fire up the timer to run every 500ms or something. I wouldn't recommend this as your actual solution, but it's a good way to confirm what's going on since everything will be processed in the same window thread.
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |