TList
BlitzMax Forums/BlitzMax Programming/TList
| ||
Is it possible to use a tlist with direct access to an index. Somethink like this: GadgetItemText$( gadget:TGadget,index ) GetListValue$(list:tlist,index) |
| ||
list.ValueAtIndex( index ) :-) |
| ||
I Brucey thanx for the Info. Now the next, is it possible to use then same for change a value at an index? |
| ||
Retrieve the object at the index Local Whatever:MyType=MyType(MyList.ValueAtIndex:Object( Index ) Change a value Whatever.x=0 |
| ||
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... |
| ||
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. |
| ||
this is one of the reasons I wrote this: ObjectList |