TLink and list again !

BlitzMax Forums/BlitzMax Beginners Area/TLink and list again !

Hi !
could you help me with this code ?
Thanks !

Strict

Type Tpoint

	Field x
	Field y

	Function Create:tpoint (x,y, who:Tinfo)
	
		Local t:tPoint = New Tpoint
		
		t.x = x
		t.y = y
		
		ListAddLast who.MyList, t
		
		Return t
		
	End Function
	
End Type

Type TInfo

	Field MyList:Tlist = CreateList()
	Field Link_Mylist : TLink = MyList.FirstLink()
	Field Value : Int
	

	Function Create:TInfo (Value : Int)
	
		Local m:TInfo = New TInfo
		m.Value = Value
		
		Return m
	
	End Function
	
	Method Add_point (x:Int, y:Int)
		tpoint.Create (x,y, Self)
	End Method
	
	Method Print_point_coordonates()
	
		Local rx, ry
		
		Link_Mylist = Link_Mylist. NextLink()
		If Link_Mylist = Null Then
			rx = -1
			ry = -1
		Else
			' how to acces to the next tpoint  x and y stored into the liste (print it or modify the value)
			' rx = ?
			' ry = ?
		End If
		DebugLog "rx = " + String (rx)
		DebugLog "ry = " + String (ry)
	
	End Method		
	
End Type

Local t:TInfo

t = tInfo.Create (10)
t.Add_point (13,13)
t.Add_point (15,18)
t.Print_point_coordonates ()
t.Print_point_coordonates ()


i want display
rx = 13
ry = 13
rx = 15
ry = 18

Strict

Type Tpoint

	Field x
	Field y

	Function Create:tpoint (x,y, who:Tinfo)
	
		Local t:tPoint = New Tpoint
		
		t.x = x
		t.y = y
		
		ListAddLast who.MyList, t
		
		Return t
		
	End Function
	
End Type

Type TInfo

	Field MyList:Tlist = CreateList()
	Field Link_Mylist : TLink = MyList.FirstLink()
	Field Value : Int
	

	Function Create:TInfo (Value : Int)
	
		Local m:TInfo = New TInfo
		m.Value = Value
		
		Return m
	
	End Function
	
	Method Add_point (x:Int, y:Int)
		Link_Mylist = MyList.FirstLink() ' < added
		tpoint.Create (x,y, Self)
	End Method
	
	Method Print_point_coordonates()
	
		Local rx, ry
		
		If Link_Mylist = Null Then
			rx = -1
			ry = -1
		Else
			' how to acces to the next tpoint  x and y stored into the liste (print it or modify the value)
			rx = tpoint(Link_Mylist.value()).x ' < Added
			ry = tpoint(Link_Mylist.value()).y ' < Added
		End If
		DebugLog "rx = " + String (rx)
		DebugLog "ry = " + String (ry)
		Link_Mylist = Link_Mylist.NextLink()
	
	End Method		
	
End Type

Local t:TInfo

t = tInfo.Create (10)
t.Add_point (13,13)
t.Add_point (15,18)
t.Print_point_coordonates ()
t.Print_point_coordonates ()



i dont really use links that much but from what i gather you needed to make sure that the link was not null (which you did,but...) which caused an error on link_mylist.nextlink() because link_mylist was null. I added a line where it sets it to first whenever you add an item (not the best way). also to get the object handle that the link refers to you use .value() and just cast it.

Having said all that, wouldn't be easir to do this:
Strict

Type Tpoint

	Field x
	Field y

	Function Create:tpoint (x,y, who:Tinfo)
	
		Local t:tPoint = New Tpoint
		
		t.x = x
		t.y = y
		
		ListAddLast who.MyList, t
		
		Return t
		
	End Function
	
End Type

Type TInfo

	Field MyList:Tlist = CreateList()
	Field Link_Mylist : TLink = MyList.FirstLink()
	Field Value : Int
	

	Function Create:TInfo (Value : Int)
	
		Local m:TInfo = New TInfo
		m.Value = Value
		
		Return m
	
	End Function
	
	Method Add_point (x:Int, y:Int)
		Link_Mylist = MyList.FirstLink() ' < added
		tpoint.Create (x,y, Self)
	End Method
	
	Method Print_point_coordonates()
	
		Local rx, ry
		
		For Local point:tpoint = EachIn mylist
			DebugLog point.x + ", " + point.y
		Next
		'If Link_Mylist = Null Then
		'	rx = -1
		'	ry = -1
		'Else
			' how to acces to the next tpoint  x and y stored into the liste (print it or modify the value)
		'	rx = tpoint(Link_Mylist.value()).x ' < Added
		'	ry = tpoint(Link_Mylist.value()).y ' < Added
		'End If
		'DebugLog "rx = " + String (rx)
		'DebugLog "ry = " + String (ry)
		'Link_Mylist = Link_Mylist.NextLink()
	
	End Method		
	
End Type

Local t:TInfo

t = tInfo.Create (10)
t.Add_point (13,13)
t.Add_point (15,18)
t.Print_point_coordonates ()


Thanks diablo !