Calling a method when a pagePanel is selected

Hello all you knowledgeable people.

I’m stuck on something that seems to me should be trivial, but I’m not finding a solution.

I want to call a method when a specific pagePanel is selected. I tried using the “Activate” event which actually works fine. If I click outside of the application and then back in the window (the expected behaviour I guess), but this, of course, is no good to me !

I’ve tried firing it from the “On Change” event of the pagePanel, but that tells me I’m making a “Static Reference to instance method” and to call it from within the instance, which is, of course, exactly what I want to do ! I’ve also tried firing a timer from the “On Change” event but I get the same error.

My controls for each of my tabs are grouped in individual ContainerControls and the method is attached to its respective pagePanel ContainerControl being selected.

I tried moving the methods into a Global Module but had no luck that way either.

Could someone please tell me what I’m missing here and how to solve this, or at least point me in the right direction?

Thanks in advance.

Have you tried something like:
NameOfContainerControlOnPagePanel.MethodToCall

You would also need some kind of Select Case / If statement to call the correct container control based on the current panel.

Thanks for your answer.
That is indeed one of the first things I tried in the PagePanel Change event, and it returns a “Static Reference to instance method” error.
So… not the solution I’m afraid.

Yeah, but what code are you using there?

The change event means you should just be able to

Call SomeMethod()

What does the errant line of code actually say?

OK… in PagePanel1 Change event, I have :

currentPage = Main.PagePanel1.SelectedPanelIndex

if currentPage = 3 then
ContainerControl1.theMethodToLaunch
end

These are the exact instructions, I have just made the names clearer for others.
Oh… and currentPage is a global variable for easy reference to the current panel.

Is ContainerControl1 the name of the container control class or the name of the control on the window?

It’s the name of the ContainerControl class. theMethodToLaunch is a method added to that class. No actual controls are involved here. Could that be the catch ? Should I add a control and put my method in the Action event ? Seems a bit weird :thinking:

How do you put the containers on the pagepanel? If you do it at design time, then the container instance will be something like ContainterControl11. If you do it in code, then you’ll need to keep a reference to the container instance as a property of the window. Eg.,

Property container3 as ContainerControl1
container3 = New ContainerControl1
container3.EmbedWithinPanel(PagePanel1, 3)

Then in PagePanel1 Change event

if currentPage = 3 then
   container3.theMethodToLaunch
end
3 Likes

Yessssss !! That was exactly it !! I was calling the container and not its instance on the PagePanel.
I should have seen that, but I’m a total newbie at Xojo.
Thank you so much for your time and your precious help.

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