Control array index numbers

The documentation says

Remember, because Control Sets are not arrays if you remove a control in the middle of the Control Set you will get a hole in the index values. For example if you have four items in a Control Set they will initially have index values of 0, 1, 2, 3. If you remove index 2 then you will have three items in the Control Set with index values of 0, 1, 3. Index value 2 will be Nil.

Is this actually correct?
I have dynamically created a set of checkboxes. Then one or more were optionally deleted. Based on the documentation I expected holes in the list but deleting seems to close the gaps, no holes in the index sequence. Makes life a lot simpler but …

I always relied on the fact that gaps are indeed removed in this case (since 20 years of programming with “Xojo”). No idea why the documentation says otherwise.

The gaps are not automatically removed if you delete elements at design time. They never have been. In this case, if you ignore the documentation, you can introduce bugs.


Ok, that seems to make sense. Delete them in the IDE and remaining instances are not renumbered. Delete in code and gaps are closed up.

I’ll try and remember that.

Perhaps the documentation could make it clearer that it’s about design time.

So, if one both deletes some in the IDE and then deletes others in code, we can assume the gaps will be removed entirely.

Assume what the documentation says but test for yourself. Be aware that the behavior could change to match the documentation or vice-versa.

One of the “facts (programming) life” I have to remind my friends about is, just because something’s in print, that doesn’t make it true. Quantum Physics aside, everything happens at a point in time and what was true at one time, may not be true later. So I always suggest that when coding for an action to happen, test it to make sure what you think happened, actually did happen.

My naivete was exposed in College Calculus class where the answers to odd numbered quiz questions (at the end of the chapter) were given in the back of the textbook. Except some of them were wrong! How could they print a calculable answer incorrectly? If it’s in print, it may be true; it may not.

Not quite. If you have a gap already, that gap will be preserved. Eg, suppose your indexes are

1, 2, 4, 5, 6, 8, 9

If you remove 5, that run of indexes will be closed up, but only that sequence. You get

1, 2, 4, 5, 8, 9

6 was moved down to 5 to close the gap you just created, but the pre-existing gaps are not crossed.

Then, IMO, that’s not worth reading the documentation in the first place. Just try.

Thanks; that’s actually what I wanted to know. (sometimes I don’t have time to launch the IDE right now to test).