I have a TList of objects which is looped over to draw them, but I wasn't sure how to remove an item, at first I was using the_list.remove self (as a method), but I had to settle with getting the link, and then removing that. But if I use the_list.contains(the_object), it returns true, but I know the the loop of the list didn't get it, what's going on?
Perhaps I simple don't understand what these commands do.
Without a code showing what you did, it sounds like you forgot some points of your code as the described thing should work. (assumed that self is the same object as the_object) (you could use self there as well)
Ok, sorry about the lack of information:
Function update_all()
Local a:TObject
For a = EachIn object_list
a.update()
Next
End Function
Method Destroy()
object_index[self.index].link.remove
If object_list.contains(Self) Then Notify "Gah"
End Method
"Gah" always shows, yet the removed objects are never looped through again.
I think it should be:
Method Destroy()
object_list.Remove(Self)
If object_list.contains(Self) Then Notify "Gah"
End Method
--Byteemoz
Gah is still notified with that, how exactly does 'contains' work?
Have you been fiddeling around with the internal structures of the linked list? Because that works:
Global object_list:TList = CreateList()
o1:TTest = New TTest
object_list.AddLast o1
o2:TTest = New TTest
object_list.AddLast o2
o3:TTest = New TTest
object_list.AddLast o3
For o:TTest = EachIn object_list
Print "Obj: " + o.ToString()
Next
o1.Destroy()
o2.Destroy()
o3.Destroy()
For o:TTest = EachIn object_list
Notify "Obj: " + o.ToString()
Next
Type TTest
Method Destroy()
object_list.Remove(Self)
If object_list.contains(Self) Then Notify "Gah"
End Method
EndType
'Contains(val:Object)' traverses all TLinks within the linked list and returns True when the value of one of them matches 'val'.
-- Byteemoz