Finding an object in a list?

BlitzMax Forums/BlitzMax Beginners Area/Finding an object in a list?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Its not very effective but you could do it this way.


Global mylist:TList=CreateList()

Type fruit
	Field name$
	
	Function FindObject:fruit(_Name:String)
		For t:fruit = EachIn mylist
			If t.name = _name Then 
				Return t
				Exit
			EndIf
			Next
			Return
	End Function
	
	Method New()
		ListAddLast mylist,Self
	End Method
	
End Type

Local f:fruit

f=New fruit ; f.name$="apple"
f=New fruit ; f.name$="banana"
f=New fruit ; f.name$="pear"
f=New fruit ; f.name$="orange"
f=New fruit ; f.name$="peach"

f = Null ' Important

f=fruit.FindObject("pear") 

If f ListRemove mylist,f

For f = EachIn mylist

Print f.name

Next