TList

BlitzMax Forums/BlitzMax Programming/TList

MacSven(Posted 2009) [#1]
Is it possible to use a tlist with direct access to an index.
Somethink like this:

GadgetItemText$( gadget:TGadget,index )

GetListValue$(list:tlist,index)


Brucey(Posted 2009) [#2]
list.ValueAtIndex( index )

:-)


MacSven(Posted 2009) [#3]
I Brucey thanx for the Info.

Now the next, is it possible to use then same for change a value at an index?


jsp(Posted 2009) [#4]
Retrieve the object at the index
Local Whatever:MyType=MyType(MyList.ValueAtIndex:Object( Index )
Change a value
Whatever.x=0


Otus(Posted 2009) [#5]
Now the next, is it possible to use then same for change a value at an index?


No, for that you could use something like:
Function SetValueAtIndex(list:TList, index:Int, value:Object)
	Assert index>=0 Else "Object index must be positive"
	Local link:TLink=list._head._succ
	While link<>_head
		If Not index link._value = value ; Return
		link=link._succ
		index:-1
	Wend
	RuntimeError "List index out of range"
End Function


However, if you need indexed access, you could just use an array...


GfK(Posted 2009) [#6]
I sometimes use an array of objects in tandem with a TList of the same data.

Why? Because while I generally prefer to use TLists, if I need all of the items indexed, ValueAtIndex is fine but can be slow on large lists. Its more convenient to do that via an array.

There's still only one set of data, but two separate methods of accessing it.


Perturbatio(Posted 2009) [#7]
this is one of the reasons I wrote this: ObjectList