Hiya,
I'm taking an educated guess to what you mean with 'to allow both the adding of first AND last depending on a variable.' so I'm assuming this:-
First you'd remove the New() method as this is a default action that you that don't want? Then in the Create(...) method add an extra variable to allow you to choose whether the new instance is to be added to the beginning or end of the TList.
Strict
Type TObject
Global all:TList = New TList
Field link:TLink
Field ident:Byte
Field xpos:Float,ypos:Float
Field fram:Byte
Field dead:Byte,squished:Byte
Field minfram:Byte,maxfram:Byte
'Method New()
' link = all.AddLast(Self)
'End Method
Method remove()
link.Remove()
link = Null 'for safety
End Method
Function Create:TObject(i,x,y,First) '<-------Added extra variable to allow First or Last position entry
Local anim:TObject = New TObject
anim.ident=i
anim.xpos=x
anim.ypos=y
If First
anim.link = all.AddFirst(anim)
Else
anim.link = all.AddLast(anim)
EndIf
Return anim '<- Not sure why you want to Return this instance, not needed in this example.
End Function
End Type
For Local i = 0 To 10
TObject.Create(0,0,0,False) 'Use True to insert First
Next
For Local anim:TObject = EachIn TObject.all
anim.Remove()
DebugLog "HHH"
Next
For Local anim:TObject = EachIn TObject.all
DebugLog "HERE"
Next
Last edited 2011
|