Container Control And PagePanels

I’m, new to Xojo and programming in general so please be gentle with me :slight_smile:

I am trying to convert a set of specific business calculators from Excel to a Xojo desktop app (Windows) and I am having difficulty with the UI.

I have a window which is split in two vertically. On the left hand side is a menu consisting of three choices (one for each of the three calculators offered). On the right hand side is the specific calculator. The idea is that you click on a menu item on the left side, and the appropriate calculator appears on the right side. Easy as pie, or so I thought.

I am using a PagePanel on the right hand side, with each of the three pages I have set up (0, 1 & 2) offering one of the three different calculators. The left hand side, which I will use as a menu, is just a blank part of the window, and will hold links to the three choices, one for each of the three calculators.

I can create buttons, labels etc for the proposed menu and add them to the left hand part of the window. I can also add the PagePanel1.value = 0 command as a MouseDown or MouseUp event in the first of the options to link to Page 0 of the PagePanel, and sure enough when it is clicked on the PagePanel displays the contents of page 0. Likewise I can do the same for the second and third pages. All good so far.

Then I thought about creating a container so that I could keep the menu separate from the rest of the controls, making things more manageable and allowing me to reuse the menu in other projects (and only worry about changing the names etc), but it is here where I have come to a sticking point.

So I create the container, add my buttons, labels or whatever and add the code as before, and add it to the main window. On compiling the debugger tells me with regards to PagePanel1, “this item does not exist”. The same setup (button, code etc) works perfectly outside the container, but if I add the controls to the container, it freaks out.

Can anyone out out where I am going wrong please?

Incidentally, it didn’t take me too long to actually program the calculators themselves, and I honestly though that would be the hard part! Although the If, Else, EndIf statement did not work the way I expected it to with the last Else statement needing to be an ElseIf before the compiler stopped complaining (didn’t make sense to me at the time either!)

Thanks in advance for your help.

Regards
Simon

Your code to switch pages is now on the Container. But the PagePanel is not on the Container. So you will get a “not exists” message because the PagePanel does not exist where you are trying to use it.

You’ll need a more sophisticated design. Events would work well for this. You could have the clicks on the Container call an event you create on the Container (Event Definition), perhaps passing in something to identify the item that was clicked. Then on the Window where you put the Container, you would add the event handler and there put the code to switch the page in the PagePanel.

Sample Project Download

Hi Paul,

how to do the same thing in web app with Xojo ?

Thanks for your help.

Jerome

[quote=227075:@JrmeLeray]how to do the same thing in web app with Xojo ?
[/quote]

PagePanel does not exist in a Web App. But you can roll something similar either with dynamic WebContainers.

Hi Paul,

Many thanks for your assistance and your sample project to show how it could be done. I have managed to implement your solution into my own project and it works wonderfully.

For my own benefit and further education…

Am I right in thinking that you cannot call an external element from within a control embedded within a container, and hence why I was getting the “Item does not exist” message when compiling? Am I right to assume that you only call elements that reside within the control itself using the original method I was using?

Am I also right in thinking that your solution worked because the action was not linked to a control within the container, but to the container itself, therefore allowing access to all other controls within the window? If not, can you explain how it works please?

I have had a look around and I cannot find a definitive answer to the questions posed here so I would appreciate a little clarification if you wouldn’t mind.

Regards
Simon

You cannot reference items that are unknown to the class you are working with. A ContainerControl is a class and it knows nothing about a Window you might place it on. So it cannot possibly call code from the Window directly. The event technique is one way around this. Another is to add a property to your Container and then set that property (from the Window) to contain a reference to the Window. Then you could write code like this:

MyWindowProperty.CalculatorPagePanel.Value = 0

I did a webinar on ContainerControls a while back, which may be useful:
Desktop Container Controls

My technique of using events works because the reference to the Window PagePanel control is not on the ContainerControl class, but is instead on the the instance of the ContainerControl that is on the Window (the event handler). Since the code is on the Window, it can directly reference controls that are also on the Window.

As Michel said, there is no PagePanel or TabPanel for web apps, but you can use a WebContainer (as shown is this example) to simulate them:

Examples/Web/Containers/TabPanelExample

Great, Thanks Paul & Michel.

you also take a peek at Graphitisuite, there is a WebPanel Control for Web:
http://www.graffitisuite.com/products/