"This item does not exist" error

I don’t get this to work. I have a button on a layout. In a Method I want to change the Enabled state to True, but keep on getting the message “This item does not exist”. Also, the button’s item name is not being predicted inside the Method, so apparently isn’t not being seen. What am I doing wrong?

The button is inside a container and that container is placed on a page panel. Maybe this has something to do with it?

Is the button private?

All controls should be private to their window or container. Make a public method in the container for enabling/disabling. Now call the method which does the enabling/disabling. You have now mastered a simple form of information hiding. When you now have a second button, or a canvas based button instead you only have to change the code in the container and not the code that calls the container.

The button on the container is set to Public. So this means the same as having it global, right?
I just discovered that creating the method in the contain, makes the button visible.

I have 8 containers, so by keeping the controls Private their functionally stays with a container and cannot interfere with the other containers?

If you want to enable the button from outside the container, you need to qualify the button name with the container name.

myContainer.myButton.enabled = true

From within the container, any method can reference the button just using the name.

Thanks, I understand it much better now. Windows and Containers are separate islands, but can be reached from the outside by starting a method with their object name.

Doing this is not recommended. I’d go so far as to say this is a bad practice.

Any control, window, container should be treated as a black box where you do NOT reach down into its guts to make changes like this. The reason ? If you DO reach down into the guts then you have a much harder time changing the innards to a better / different implementation without also changing everything that does reach into it from outside.

If you create a method on the Container that is like

    Sub ButtonEnabled(assigns isEnabled as boolean)
                 myButton.enabled = isEnabled
    end sub

then that previous code turns into

   myContainer ButtonEnabled = true

And, should you ever decide to rename the button or make some other change to your container you only change the code in the method already on the container (the API you exposed to the rest of your program) and NONE of the rest of your program has to change.

And how is this related to the menu handlers? It seems that they also only work when placed inside a container.

You can add menu handlers to the container as well

Yes, but doing that, I cannot connect to the MenuItem, its name does not appear in the Inspector to choose from. That drop down menu is empty.

Sorry, I accidentally marked the question as Answered above and don’t see a way to undo that.

Choose the ContainerControl (the original I suppose, unsure), and a MenuHandler.

In the right Pane, you will see a PopupMenu that allows you to choose the MenuItem,
the code can be added in the Code Editor (mid and large pane).

[quote=441979:@Emile Schwarz]Choose the ContainerControl (the original I suppose, unsure), and a MenuHandler.

In the right Pane, you will see a PopupMenu that allows you to choose the MenuItem,
the code can be added in the Code Editor (mid and large pane).[/quote]

That’s what I tried, but the MenuItem is not in PopupMenu to choose from, meaning that it is not reachable from here, right?

If it is in a brand new window YOU add to your project, start by assigning it a MenuBar…

No: read my previous answer.

Did you read the ntroduction to Programming Book ?
(http://www.xojo.com/learn)

No, I didn’t see this before. Must have missed it. I did create the example projects and of course after working with FileMaker for 3 years, wanted to continue at the same speed in Xojo. Thanks for the link, I will study this book first.

What about the window question below:

If it is in a brand new window YOU add to your project, start by assigning it a MenuBar…

If you mouse over the post at the top of this thread, you will see an X in the corner of the inline answer, click that to cancel the answered post.

If that doesn’t work then try assigning another post as the answer, then cancel that one in the same way as mentioned above.

[quote=442016:@Emile Schwarz]What about the window question below:

If it is in a brand new window YOU add to your project, start by assigning it a MenuBar…

No, it’s not a window I added myself, but it does have 8 Containers.

And… did you add MenuHandler(s) in the Menu Editor (the one you will want to select) ?

I have to confess that at this point I am starting to be at loss of ideas…

Yes, I added menu handlers all over the place by now. Nothing works. I better abandon my current project and starts from scratch. My lack of Xojo is what is giving me problems here.