Hi,
my next TList problem :-(
For sure in a For EachIn loop I can list any items of a TList and the one of sublists.
But how do I access only the entrys of "Test 2"?
Type trainer
Global ltrainers:TList
Field ltlink:TLink,name:String
Method New()
If Not ltrainers ltrainers=CreateList()
Local ltlink:TLink=ListAddLast(ltrainers,Self)
Self.ltlink=ltlink
End Method
Function AddTrainer:trainer(name:String)
Local t:trainer = New trainer
t.name=name
Return t
End Function
End Type
Type stable
Global lstables:TList
Field name:String
Field ltrainers:TList
Function AddStable:stable(name:String)
Local s:stable = New stable
s.name = name
Return s
End Function
Method New()
If Not lstables lstables=CreateList()
ListAddLast lstables,Self
ltrainers=CreateList()
End Method
Method AddTrainer:trainer(trainers:trainer)
Local t:trainer=trainers
ListAddLast ltrainers,t
Return t
End Method
End Type
Local t:trainer
Local s:stable
Local name:String,x:Byte
For x=0 To 9
ReadData name
t=trainer.addtrainer(name)
Next
For x=0 To 2
ReadData name
s=stable.addstable(name)
SeedRnd MilliSecs()
For t=EachIn trainer.ltrainers
Local y:Byte=Rand(3)
If y=3 Then
s.AddTrainer(t)
t.ltlink.Remove
EndIf
Next
Next
Print "Items: " + CountList(trainer.ltrainers)
'Instead the whole listing I like only to get the ltrainers of Test 2
For s=EachIn stable.lstables
Print s.name
For t=EachIn s.ltrainers
Print t.name
Next
Next
s.lstables.First
s.lstables.ValueAtIndex(1)
For t=EachIn trainer.ltrainers
Print "~tFree Trainer: " +t.name
Next
Print "Items: " + CountList(trainer.ltrainers)
DefData "Geli"
DefData "Frank"
DefData "Jochen"
DefData "Susi"
DefData "Doro"
DefData "Karl"
DefData "Jurgen"
DefData "Dieter"
DefData "Sigrid"
DefData "Babsi"
DefData "Test 1"
DefData "Test 2"
DefData "Test 3"
my next TList problem :-(
For sure in a For EachIn loop I can list any items of a TList and the one of sublists.
But how do I access only the entrys of "Test 2"?
Type trainer
Global ltrainers:TList
Field ltlink:TLink,name:String
Method New()
If Not ltrainers ltrainers=CreateList()
Local ltlink:TLink=ListAddLast(ltrainers,Self)
Self.ltlink=ltlink
End Method
Function AddTrainer:trainer(name:String)
Local t:trainer = New trainer
t.name=name
Return t
End Function
End Type
Type stable
Global lstables:TList
Field name:String
Field ltrainers:TList
Function AddStable:stable(name:String)
Local s:stable = New stable
s.name = name
Return s
End Function
Method New()
If Not lstables lstables=CreateList()
ListAddLast lstables,Self
ltrainers=CreateList()
End Method
Method AddTrainer:trainer(trainers:trainer)
Local t:trainer=trainers
ListAddLast ltrainers,t
Return t
End Method
End Type
Local t:trainer
Local s:stable
Local name:String,x:Byte
For x=0 To 9
ReadData name
t=trainer.addtrainer(name)
Next
For x=0 To 2
ReadData name
s=stable.addstable(name)
SeedRnd MilliSecs()
For t=EachIn trainer.ltrainers
Local y:Byte=Rand(3)
If y=3 Then
s.AddTrainer(t)
t.ltlink.Remove
EndIf
Next
Next
Print "Items: " + CountList(trainer.ltrainers)
'Instead the whole listing I like only to get the ltrainers of Test 2
For s=EachIn stable.lstables
Print s.name
For t=EachIn s.ltrainers
Print t.name
Next
Next
s.lstables.First
s.lstables.ValueAtIndex(1)
For t=EachIn trainer.ltrainers
Print "~tFree Trainer: " +t.name
Next
Print "Items: " + CountList(trainer.ltrainers)
DefData "Geli"
DefData "Frank"
DefData "Jochen"
DefData "Susi"
DefData "Doro"
DefData "Karl"
DefData "Jurgen"
DefData "Dieter"
DefData "Sigrid"
DefData "Babsi"
DefData "Test 1"
DefData "Test 2"
DefData "Test 3"