Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - Report Control crash when deleting items
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Report Control crash when deleting items

 Post Reply Post Reply
Author
Message
JemeraldSoft View Drop Down
Newbie
Newbie


Joined: 18 October 2006
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote JemeraldSoft Quote  Post ReplyReply Direct Link To This Post Topic: Report Control crash when deleting items
    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.
Back to Top
rmercer View Drop Down
Groupie
Groupie


Joined: 22 February 2006
Status: Offline
Points: 34
Post Options Post Options   Thanks (0) Thanks(0)   Quote rmercer Quote  Post ReplyReply Direct Link To This Post Posted: 18 October 2006 at 3:21pm
Did you call Populate() after you removed the record?
 
m_lstAlarm.GetRecords()->RemoveAt(index);
m_lstAlarm.Populate();
 
Back to Top
JemeraldSoft View Drop Down
Newbie
Newbie


Joined: 18 October 2006
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote JemeraldSoft Quote  Post ReplyReply Direct Link To This Post Posted: 18 October 2006 at 6:33pm
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();

Back to Top
JemeraldSoft View Drop Down
Newbie
Newbie


Joined: 18 October 2006
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote JemeraldSoft Quote  Post ReplyReply Direct Link To This Post Posted: 18 October 2006 at 6:36pm
I also tried delete the row before deleting the record:
m_lstAlarm.GetRows()->RemoveAt(i);
Back to Top
rmercer View Drop Down
Groupie
Groupie


Joined: 22 February 2006
Status: Offline
Points: 34
Post Options Post Options   Thanks (0) Thanks(0)   Quote rmercer Quote  Post ReplyReply Direct Link To This Post Posted: 19 October 2006 at 10:50am
Originally posted by JemeraldSoft JemeraldSoft wrote:

I also tried delete the row before deleting the record:
m_lstAlarm.GetRows()->RemoveAt(i);
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.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.