My list returns TLinks, how do it get my object?
BlitzMax Forums/BlitzMax Beginners Area/My list returns TLinks, how do it get my object?
| ||
Excuse the typo in the thread title. I've got a type, "folder", of which I have been creating instances and adding to the list "list_folder". Now, I need to go back through the list, and I'm starting with this: cfolder:folder=list_folder.firstlink() Doesn't work. It says "Unable to convert from 'TLink' to 'folder'". What am I doing wrong, how can I get my 'folder' object back out of the list? If I use .value() on the end of the above, I get "Unable to convert from 'Object' to 'folder'". I'm really getting to like BMax, but man alive, it's been a horrible horrible learning curve. |
| ||
Cast value back to folder...Type tfolder Global tfolder_list:tlist=CreateList() Field x Function create(num:Int) Local a:tfolder = New tfolder a.x = num ListAddLast tfolder_list , a End Function End Type For x = 1 To 10 tfolder.create(x) Next test:tfolder = tfolder(tfolder.tfolder_list.firstlink().value()) Print test.x |
| ||
or use tfolder(tfolder.tfolder_list.first()) if you aren't using the links anyway. (at the moment they are a little pointless as several internal functions break them like reverse etc) |
| ||
Huh, I tried various combinations of that, but I didn't think of actually putting the list in with the type. Thanks again, Tony! Your post helped me figure out the rest in the end as well. Seems like the easiest way is to keep a TLink around to navigate the list, and update the object pointer from it each time. Tedious, but I'll get used to it. I'll be using EachIn the vast majority of the time anyway, so I guess I can't complain. Dream: I was looking at using that, but I wasn't really sure if that was the best way to do it. Noted for future reference, thank you! |
| ||
As Dreamora says there is a problem with reverselist which I have reposted (as still not fixed). However, you need the link to use prevlink/nextlink and I am not sure how to do the same with lists. Mark stated in another thread that we should never have to use links directly but didn't give much info on what we should use instead. |