Hi
I’ve got an Array where some Class-Instances are inside.
var PbsToRelease() as Mod_Playback.Playback
Now at some time, some Class-Instances should be remove themself.
In only know the method with .removeAtRow(x) … but in my case I don’t know the index of each Element because the element inside the Array should destroy/remove itself.
I wanna call a method of the instance to remove itself from the array.
How is that possible?
Thank you, Markus.
If you keep a reference to the array you can do:
theArray.removeAtRow(theArray.IndexOf(instance))
If there is an updated name for IndexOf with the API2 array naming nonsense youll need to use that instead
Thank you Jason, I didn’t know that IndexOf will work with Classobjects!
have the constructor get a reference to the array and then when this “playback” is at the point it should remove itself it can find itself in the array and remove itself
Class Playback
whatArray() as Mod_Playback.Playback
Sub Constructor( arrayImIn() as Mod_Playback.Playback)
self.whatArray = arrayImIn
End Sub
Sub EndMe()
if whatArray is nil then
return
end if
dim index as integer = whatarray.indexof(self)
if index < 0 then
return
end if
// note if this is the last reference
// then we'll see the destructor run next
whatArray.remove index
End Sub
End Class
and add new ones like
var PbsToRelease() as Mod_Playback.Playback
PbsToRelease.append new Mod_Playback.Playback(pbsToRelease)
note you cant use the destructor since the instance is in an array and until the item is nil’d theres a reference so the destructor wont be executed
edit - this is entirely written in the forum editor so there may be syntax errors