Book a Demo

Author Topic: Different positions for GetAt(i) and Delete(i)  (Read 6853 times)

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Different positions for GetAt(i) and Delete(i)
« on: August 22, 2020, 01:41:41 am »
Hi,

I do the following:

Connector.ConveyedItems.GetAt(i);
Connector.ConveyedItems.Delete(i);

Delete(i) deletes another element than I get with GetAt(i). Why?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Different positions for GetAt(i) and Delete(i)
« Reply #1 on: August 22, 2020, 02:51:04 am »
No it won't.

I have used this countless times in my code.
I'm guessing there must be something else that messes up something.

A best practice to delete stuff from a list is to iterate it backwards (from count-1 to 0) to avoid invalid indexes.

Geert

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Re: Different positions for GetAt(i) and Delete(i)
« Reply #2 on: August 22, 2020, 03:01:36 am »
No it won't.
I have used this countless times in my code.
I'm guessing there must be something else that messes up something.
A best practice to delete stuff from a list is to iterate it backwards (from count-1 to 0) to avoid invalid indexes.
Geert

I learned from you to iterate backwards :)

There is no code between the two methods. I do not understand what can happen between the methods. I added an item before. I tried with update and / or refresh before. Same thing :(

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Re: Different positions for GetAt(i) and Delete(i)
« Reply #3 on: August 22, 2020, 03:06:52 am »
Mayby I misunderstood C#

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();
« Last Edit: August 22, 2020, 04:05:45 am by Viking »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Different positions for GetAt(i) and Delete(i)
« Reply #4 on: August 22, 2020, 04:00:53 am »
Code seems fine to me. (except for a lost "{", but I guess that is not in your actual code)

I've never deleted from the ConveyedItems, but it would be really surprised if there would be a difference between DeleteAt() and GetAt()
None of the other EA.Collections seems to have this problem.
If you can create a reproducible example, I would definitely report it as a bug.

Geert

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Re: Different positions for GetAt(i) and Delete(i)
« Reply #5 on: August 22, 2020, 04:04:48 am »
Code seems fine to me. (except for a lost "{", but I guess that is not in your actual code)
I've never deleted from the ConveyedItems, but it would be really surprised if there would be a difference between DeleteAt() and GetAt()
None of the other EA.Collections seems to have this problem.
If you can create a reproducible example, I would definitely report it as a bug.
Geert

I never had these problems with other Collections.

Yes, I also think that it is a bug.

If it is a bug, how long do I have to wait for a solution?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Different positions for GetAt(i) and Delete(i)
« Reply #6 on: August 22, 2020, 04:41:21 am »
Well, from the next release to infinity you have a nice choice.

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: Different positions for GetAt(i) and Delete(i)
« Reply #7 on: August 22, 2020, 02:50:44 pm »
If it is a bug, how long do I have to wait for a solution?

You don't really know. I've had bugs fixed within two weeks of reporting, but some other bugs I've reported years ago have yet to be fixed

It all depends a bit on think like
- is it an obvious bug (or just weird behavior)
- is there a workaround
- is it an area that has been worked on recently
- ....
- ... luck?

Geert

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Re: Different positions for GetAt(i) and Delete(i)
« Reply #8 on: August 23, 2020, 08:27:56 pm »
The workaround is:

(1) Create an own collection (List), add or not (delete) elements from Connector.ConveyedItems to this collection and add new ConveyedItems, if needed.
(2) Delete all Connector.ConveyedItems with Connector.ConveyedItems.Delete(i);
(3) Add all elements from the own collection to Connector.ConveyedItems with Connector.ConveyedItems.AddNew(ElementGUID, null)
(4) Connector.update().
« Last Edit: August 23, 2020, 08:29:56 pm by Viking »