Accessing objects in a list

BlitzMax Forums/BlitzMax Beginners Area/Accessing objects in a list

Leo Santos(Posted 2006) [#1]
Hey,

How do i access directly the object that is being "pointed" by a link in a list?

For example:

Strict

Type TMytype	
	Field Z = 100	
End Type

Local Mylist:TList = CreateList()

Local Test01:TMytype = New TMytype
MyList.AddLast Test01

Local Test02:TMytype = New TMytype
MyList.AddLast Test02

If test02 = Mylist.Last Then Print test02.Z


In this case, I want to print "Z" field only if Test02 is the last on the list. But I get a "Types 'TMytype' and 'Object()' are unrelated". While I understand the error, I don't know how to get around it.

Also, can I access an object like Mylist.last.Z ? (it doesn't work with the "last" method).

And while I'm at it... are there any tutorials on using lists and objects? I did some basic ones, but I'm afraid I didn't find nearly as many examples under different situations as I'd like.

Thanks!


EOF(Posted 2006) [#2]
Just a couple of brackets missing there..

.List()

Strict

Type TMytype
	Field Z% = 100
End Type

Local Mylist:TList = CreateList()

Local Test01:TMytype = New TMytype
MyList.AddLast Test01

Local Test02:TMytype = New TMytype
MyList.AddLast Test02

' compare last object in list
If test02 = Mylist.Last() Print test02.Z

' cast 'object' from list to 'TMytype'
Local Test03:TMytype=TMytype(Mylist.Last())
Print Test03.z



EOF(Posted 2006) [#3]
Here are a couple of examples I wrote to aid me.
They might help you ..

Using links with lists:


Cursor UP/DOWN example for lists:



Leo Santos(Posted 2006) [#4]
Hey, thanks!

You guys are always very helpful whenever my brain hits a wall and can't move forward anymore... :-)