Remove Object from List
BlitzMax Forums/BlitzMax Beginners Area/Remove Object from List| 
 | ||
| Hey. I searched for this on the forum, but couldn't find anything I could really use, so I am asking you: How do I remove a certain object (of a type I created) from a list after I wrote a compare method for that type? example : _____________________ Type car Field a Field b Field c Method Compare:Int(Other:Object) If other=Null Return 0 If a=car(other).a Return 0 If a<car(Other).a Then Return 1 Else Return -1 End Method End Type _________________________ Let's say there are 10 instances of 'car' stored in 'list'. How do I remove car3:car from that list? Thanks a lot! I really need your help ;) Lukasha. | 
| 
 | ||
| method a: 
Type car
  Field listLink:TLink
  global list:TList = CreateList()
  Function Add(newCar:car)
    newCar.listLink = list.AddLast(newCar)    
  End Function
  Method RemoveFromList()
    newCar.remove()
  End Method
End Type
Else just do: carList.remove(car3) This will loop through the list and delete the car referenced as car3. If car3 is another object, but shares the same "carID" or "name"or ... you will have to loop by your own 
  for local myCar:car = eachin carList
    if myCar.carID = searchedCar.carID then return myCar 'or carList.remove(myCar);exit
  next
bye Ron | 
| 
 | ||
| Thanks a lot for the quick reply. I'm going to try it as soon as I got time. Cheers. | 
| 
 | ||
| Thanks again. It works fine. |