Finding an object in a list?

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

Why not just give your object a compare method? FindLink will use it.

Type TMe
	Field name:String
	
	Function Create:TMe(n:String)
		Local x:TMe=New TMe
		x.name=n
		Return x
	EndFunction
	
	Method ToString:String()
		Return name
	EndMethod
	
	Method Compare:Int(o:Object)
		other:TMe=TMe(o)
		If other
			If name=other.name
				Return 0
			ElseIf name<other.name
				Return -1
			ElseIf name>other.name
				Return 1
			EndIf
		EndIf
	EndMethod
EndType


Local l:TList

l=New TList

l.AddLast(TMe.Create("AB"))
l.AddLast(TMe.Create("BB"))
l.AddLast(TMe.Create("BC"))

link:TLink=l.FindLink(TMe.Create("BB"))

DebugLog link.value().tostring()