Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: bilon on June 27, 2019, 11:44:01 pm

Title: Collection Delete method
Post 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?
Title: Re: Collection Delete method
Post by: Geert Bellekens on June 27, 2019, 11:47:06 pm
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
Title: Re: Collection Delete method
Post by: bilon on June 28, 2019, 12:13:05 am
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?
Title: Re: Collection Delete method
Post by: qwerty on June 28, 2019, 12:23:27 am
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.
Title: Re: Collection Delete method
Post by: Geert Bellekens on June 28, 2019, 02:47:39 am
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
Title: Re: Collection Delete method
Post by: qwerty on June 28, 2019, 04:37:58 am
but I don't trust that.
Me neither, so one Sparxian said it were safe :o)

q.