How do you delete a user defined type once it is created?
The docs show the command 'delete' but it says its for future expansion.
The docs show the command 'delete' but it says its for future expansion.
Method freeMedPak() if self.quiz:TMedPakQuiz <> null For Local n:TMedPakQuiz = EachIn self.quizList:TList n.free() next end if End Method
Method freeMedPak() if quiz then quizList.Clear() FlushMem End Method
Type TSomeType Global TypeList:TList Global Count:Int Field Param:Int Method New() If TypeList = Null Then TypeList = New TList ListAddLast(TypeList,Self) Count :+ 1 End Method Method Delete() Count :- 1 End Method Function Create:TSomeType(Param:Int) Local tst:TSomeType = New TSomeType tst.Param = Param Return tst End Function Function Update() For Local tst:TSomeType = EachIn TSomeType.TypeList TSomeType.TypeList.Remove(tst) FlushMem Print "Number of objects: "+TSomeType.TypeList.Count() Next End Function End Type For Local i:Int = 0 To 10 TSomeType.Create(i) Next TSomeType.Update()
Type TSomeType Global TypeList:TList Global Count:Int Field Param:Int Method New() If TypeList = Null Then TypeList = New TList ListAddLast(TypeList,Self) Count :+ 1 End Method Method Delete() Count :- 1 End Method Function Create:TSomeType(Param:Int) Local tst:TSomeType = New TSomeType tst.Param = Param Return tst End Function Function Update() For Local tst:TSomeType = EachIn TSomeType.TypeList TSomeType.TypeList.Remove(tst) FlushMem Print "Number of objects: "+TSomeType.TypeList.Count() Next End Function End Type Print "memory alloced start: "+MemAlloced() For Local i:Int = 0 To 1000 TSomeType.Create(i) Next TSomeType.Update() Print "memory alloced end: "+MemAlloced()
' randomize a list of items in a list Global list:TList=CreateList() Global memory1:Int Global memory2:Int Type foodtype Field name$ Field price# Method Add(n$,p#) Local f:foodtype=New foodtype f.name$=n$ ; f.price=p ListAddLast list,f EndMethod Method ShowList() Print "----------------------" For Local f:foodtype=EachIn list Print f.name$+" - "+f.price Next EndMethod Method RandList(numtimes=3) For Local n=1 To numtimes For Local f:foodtype=EachIn list If Rnd()>0.3 ListRemove list,f ListAddLast list,f FlushMem EndIf Next Next EndMethod End Type SeedRnd MilliSecs() For Local i = 0 To 1000 Local f:foodtype f=New foodtype f.Add "pizza",2.50 f.Add "sausage",0.75 f.Add "pie",1.53 f.Add "onion",0.21 f.Add "soup",0.97 f.Add "crisps",0.29 Next memory1 = MemAlloced() f.ShowList Print "~nrandom ..." f.RandList(1) memory2 = MemAlloced() f.ShowList Print "*****************************************************************" Print "Memory allocated after object creation: "+memory1 Print "Memory allocated after randomizing: "+memory2 Print "*****************************************************************" DebugStop End