Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: bilon on June 27, 2019, 11:44:01 pm
-
There are two methods for deleting items in the Collection class, Delete and DeleteAt. But everywhere in the sample scripts and here in this forum are just examples using DeleteAt method. Could give me a example of using Delete method. And what's that parameter of it?
-
The documentation in the help seems to be clear enough. https://sparxsystems.com/enterprise_architect_user_guide/14.0/automation/collection.html (https://sparxsystems.com/enterprise_architect_user_guide/14.0/automation/collection.html)
Can you explain what isn't clear?
Geert
-
Does it mean, that the Delete and DeleteAt methods are in fact same? If it is so, is there any possibility to delete from collection when iterating it with For Each construct?
-
Yes, they are the same except for the parameter count. What I do to be save is to save the indices which should be deleted and call the Delete(at) from the last to the first. That will be safe in eternity (or at least in most cases).
q.
-
I always iterate backward over the collection and then delete elements where needed.
Never had any issues with that.
In theory you should also be able to iterate forwards if you delete without refreshing (the elements stay in the collection, but are marked as deleted) but I don't trust that.
Geert
-
but I don't trust that.
Me neither, so one Sparxian said it were safe :o)
q.