TList sorting problem...
BlitzMax Forums/BlitzMax Programming/TList sorting problem...
| ||
Hi, There seems to be a bug with sorting raw integers in lists. ' ' works with strings List:TList = CreateList() List.AddLast("hi") List.AddLast("i'm") List.AddLast("ok") List.Sort() ' ' but not with integers List:TList = CreateList() List.AddLast(13) List.AddLast(10) List.AddLast(11) List.Sort()It seems that the references to integers (and I assume other simple types, ie. float, double, byte etc), are lost during the sorting process. [edit] Nope, the other types refuse to be converted to an object, so it looks like it only applies to integers. |
| ||
As you are not using Strict and AddLast expects objects the compiler is interpreting your integers as object handles. |
| ||
Hi, I see, but that brings up another interesting thing: Strict ' ' but not with integers Local List:TList = CreateList() Local temp:Int = 12 List.AddLast(temp) List.AddLast(Object(temp)) List.Sort()Is it impossible to store integers in a TList then? Not sure why you would do it, but I guess it could be useful in some cases. |
| ||
TLists are for storing objects only. Strings are in fact objects too. This works though: SuperStrict Local List:TList = New TList List.AddLast String("13") List.AddLast String("10") List.AddLast String("11") List.Sort For Local l$=EachIn List Print Int(l$) Next |
| ||
This seems to crop up regularly. You could also make a TInteger "wrapper" type with a single integer field... Doc update to make it clear? |