Author Topic: Collection Delete method  (Read 3410 times)

bilon

  • EA User
  • **
  • Posts: 85
  • Karma: +0/-0
    • View Profile
Collection Delete method
« 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?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Collection Delete method
« Reply #1 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
Can you explain what isn't clear?

Geert

bilon

  • EA User
  • **
  • Posts: 85
  • Karma: +0/-0
    • View Profile
Re: Collection Delete method
« Reply #2 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?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Collection Delete method
« Reply #3 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.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Collection Delete method
« Reply #4 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

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Collection Delete method
« Reply #5 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.