Is there any way to make a list of variable length as a parameter to a type?
Type Model
Field Children[]
EndType
Use a linked list.
Type Model
Global Root:TList = New TList
Field Children:TList = New TList
Field Parent:Model
Field Link:TLink
Method AddChild( c:Model )
If c Then c.SetParent( Self )
End Method
Method GetChild:Model( idx% )
Return Model(Children.GetValue( idx )) ' Cast from Object to Child on return
End Method
Method SetParent( p:Model )
If Link Then Link.Remove( )
Parent = p
If p Then
Link = p.Children.AddLast( Self )
Else
Link = Root.AddLast( Self )
EndIf
End Method
End Type
Doesn't that already work? Just use New when you want to give it a size.
Yeah you declare arrays with new and assign them to your variable. Can't remember the syntax off the top of my head.
[Code]SuperStrict
Type Model
Field myChildren:Children[]
EndType
Type Children
Field something:Int
EndType
Local myModel:Model = New Model
myModel.myChildren = New Children[8]
myModel.myChildren = myModel.myChildren[..5]
Print myModel.myChildren.length[/Code]
Might have overdone this - but as Azathoth and Nomen luni said, just use new.
Using arrays for this is a bad idea. The time it takes to resize an array is variable, adding a link to a linked list is near constant and far more efficient.