Re: Gambit, i need some suggestions


2004-06-23 09:49:10 AM
cppbuilder19
"Greg Stantin" < XXXX@XXXXX.COM >wrote in message
Quote
When accessing the items in the MessageData struct, can
it be accessed by the index of the listview?
If each List item cooresponds to an entry in the MessageData list, and in
the same order, then yes. Or, since you stored the particular MessageData
pointer into the List item Data property, then you would be able to access
the MessageData directly.
Quote
This definitely did not work, caused a crash.
As well it should. You tried to delete the Message data a second time after
it was already freed, and even then you are not even accessing the proper
entry to begin with since the indexes changed when Remove() was called. I
didn't mean for you to try to 'delete' the MessageData pointer a second
time, only to Remove() it from the original TList. In fact, I have myself
to blame for that, since my code was already doing exactly that via the
List->Remove() call, and then I told you to do it again. My fault, not
yours.
Quote
if((ListItem->Data) && (List->Remove(ListItem->Data) != -1))
That statement is already removing the message data from the original TList
that is stored in the TreeNode.
Quote
delete static_cast<TMessageData*>(ListItem->Data);
That value is freeing the MessageData item that was removed from the TList.
Quote
TMessageData *MessageData = (TMessageData*)
List->Items[ListView1->ItemIndex];
You are now trying to retreive a new MessageData using an index that is no
longer valid, since the item was removed from the TList via Remove() and
thus is no longer found at the ListItem's index. Get rid of that code, it
is not needed.
Quote
delete MessageData;
Same with this, get rid of it, it is not needed.
Quote
The same will apply for the treenode, but i have not gotten there yet :)
Accessing the TreeNodes is very different than accessing ListItems.
Gambit