Popupmenu LastAddedRowIndex issue returns wrong value


I have a strange bug when populating a popupmenu via the constructor of a container.

I have a button that create a container (stored as a property) and embed it in the right side of a window.

In the constructor of this container, I call some init (default name I gave them) methods to load controls.

When adding rows to the popupmenu, I use AddRow method and right after it, use LastAddedRowIndex to set the RowTag (via RowTagAt) of the last added row.

The issue is that LastAddedRowIndex always returns -1 in this case but the rows are added.

If I call the init of the container with an other button (and not within the constructor), LastAddedRowIndex returns the right values.

Maybe I do not get something but I created a workaround. I can easily use a workaround to make it works but I do not know if it’s a bug or not.

Here the link for feedback with the small project included.


OS X 10.14.6
Xojo 2020r2.1

Things seems worse. RowCount ends with 0 after 4 “successful” AddRow(string)

It looks like the control isn’t yet ready in the constructor method. Not sure if that’s not expectable :thinking:

Use the open event instead of the constructor event!

1 Like

I learned from this example that Xojo has the dangerous feature of being able to have half initialized components “ready” silently failing.

I wouldn’t say it’s failing. The OP is trying in the constructor to do things with other controls before the control in question is ready. In the constructor, just do stuff to initialise that control. Same applies to the popup menu. Add the rows to that in the Open event of the popup menu.

1 Like

That should fire exceptions, not working in a inconsistent way causing unpredictable results.

So make a feature request. I think more useful, however, would be to suggest some text to improve the documentation, along the lines of warning that work done in a constructor should be limited to initialising that control only.

What I said is obvious, but known. Non initialized controls would not silent fail, but it probably hits some internal things on how Xojo works, and here it must be that way. In the past I already asked questions about the lifecycle of a Xojo object and found things like this before that I wasn’t used to, from other frameworks. We usually get the component or working or not instantiated, but in Xojo we have it instantiated but not completed until the open event occurs (there’s a hidden step setting properties before the open event and AFTER the constructor, and who knows what more). :thinking: I already received the “it is this way” before, so, no new feature request, I need to get used to it.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.