Blitz2D/3D/+ like type access...

BlitzMax Forums/BlitzMax Tutorials/Blitz2D/3D/+ like type access...

Fredborgs example can be simplified a little to make it more transportable to other Types:
'Old style Blitz lists by fredborg
'beak tweak

Type mytype
	Field _value:Int	= 0

	'
	' Global list which holds all instances
	Global _list:TList

	'
	' This adds a new instance to the global list
	Method New()
		If _list = Null
			_list = New TList
		EndIf
		_list.addlast(Self)
	EndMethod
	
	'
	' Gets the next instance in the global list
	Method After:mytype()
		Local link:TLink = ListFindLink(_list,Self).NextLink()
		If link
			Return mytype(link.Value())
		Else
			Return Null
		EndIf
	EndMethod

	'
	' Gets the previous instance in the global list
	Method Before:mytype()
		Local link:TLink = ListFindLink(_list,Self).PrevLink()
		If link
			Return mytype(link.Value())
		Else
			Return Null
		EndIf
	EndMethod
	
	'
	' Removes this instance from the list
	Method Destroy()
		_list.remove(Self)
	EndMethod
	
	'
	' Removes all instances
	Function DestroyEach()
		_list.clear()
	EndFunction
	
	'
	' Gets the last instance in the list
	Function Last:mytype()
		Return mytype(_list.last())
	EndFunction

	'
	' Gets the first instance in the list
	Function First:mytype()
		Return mytype(_list.first())
	EndFunction
		
End Type

'
' Lets create a bunch of dummy type instances
For i = 0 To 5
	m:mytype = New mytype
	m._value = i
Next

'
' For..EachIn
Print "Going through each instance, using a For..EachIn loop"
For m:mytype = EachIn mytype._list
	Print m._value
Next
Print "---~n"

'
' While..Wend (forward)
Print "Going through each instance, using a While..Wend loop"
m:mytype = mytype.first()
While m
	Print m._value
	m = m.after()
Wend
Print "---~n"

'
' While..Wend (backward)
Print "Going Backwards through each instance, using a While..Wend loop"
m:mytype = mytype.last()
While m
	Print m._value
	m = m.before()
Wend
Print "---~n"

'
' Destroy
Print "Removing the first instance, and showing remaining instances"
m:mytype = mytype.first()
m.Destroy()
For m:mytype = EachIn mytype._list
	Print m._value
Next
Print "---~n"

'
' DestroyEach
Print "Removing each instance, and showing whats left"
mytype.DestroyEach()
For m:mytype = EachIn mytype._list
	Print m._value
Next
Print "---~n"

Print "That's all folks!"