Book a Demo

Author Topic: Conveyed Items: Different positions for GetAt(i) and Delete(i)  (Read 6160 times)

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Code: [Select]
for (short i = (short)(Conn.ConveyedItems.Count - 1); i >= 0; i--)
{
  ConvItem = Conn.ConveyedItems.GetAt(i);
  if (ConvItem.ElementGUID == Elem.ElementGUID) {
    Conn.ConveyedItems.DeleteAt(i,true); // same problem with false
  }
}
Conn.Update();

If I run this code, it does not delete ConvItem. It deletes another item in the collection. It only happens if ConveyedItems > 1. If there is only 1 item, everything is fine.

I never had problemes with collections before. I tried a lot of alternatives. That's why and because Geert Bellekens recommends it I report it as a bug.

See also https://www.sparxsystems.com/forums/smf/index.php/topic,44835.msg263969.html#msg263969

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Conveyed Items: Different positions for GetAt(i) and Delete(i)
« Reply #1 on: August 22, 2020, 04:42:14 am »
A bug is not reported here but with the bug report in the Support section below.

q.

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Re: Conveyed Items: Different positions for GetAt(i) and Delete(i)
« Reply #2 on: August 22, 2020, 04:44:21 am »
Conn.ConveyedItems.DeleteAt(i + 1,true);

This works. Maybe there is a rule, so that I can use it as an intermediate solution.

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Re: Conveyed Items: Different positions for GetAt(i) and Delete(i)
« Reply #3 on: August 22, 2020, 04:46:48 am »
A bug is not reported here but with the bug report in the Support section below.
q.

Many thanks @qwerty. I did not know. This section is called "Bugs and Issues" ...

I follow your recommendation :)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Conveyed Items: Different positions for GetAt(i) and Delete(i)
« Reply #4 on: August 22, 2020, 05:55:43 am »
You're not the first one being mislead ;-)

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Conveyed Items: Different positions for GetAt(i) and Delete(i)
« Reply #5 on: August 22, 2020, 02:44:24 pm »
Conn.ConveyedItems.DeleteAt(i + 1,true);

This works. Maybe there is a rule, so that I can use it as an intermediate solution.
You would get an index out of bounds if you tried that on the last item of the collection wouldn't you?

Geert

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Re: Conveyed Items: Different positions for GetAt(i) and Delete(i)
« Reply #6 on: August 23, 2020, 08:21:29 pm »
Conn.ConveyedItems.DeleteAt(i + 1,true);

This works. Maybe there is a rule, so that I can use it as an intermediate solution.
You would get an index out of bounds if you tried that on the last item of the collection wouldn't you?
Geert

That's true, Geert. The solution is much easier.

I report it in in the initial thread https://www.sparxsystems.com/forums/smf/index.php/topic,44835.0.html.