No PopUpMenu on a ContainerControl?

I have designed a ContainerControl I embed on a window if needed. But the GUI was overloaded, therefore I replaced the SegmentedControls on the Container by PopUpmenus and rearranged the code. But now when I try to instantiate a new ContainerControl, I get an illegal cast exception because “PopUpmenu cannot be cast to a ContainerControl”. Does that mean I cannot use them on a container or did I do something else wrong?

Besides that, I would have used NSSegmentedControls with Icons rather – but (beside the MBS plugins) they don‘t seem to be available, at least not in MacOSLib. I can understand that; they are a big chunk to declare. But I still have the idea someone could have made them available somewhere – is that so?

I use popups on containercontrols without problems. It seems more that your casting is wrong. From the errir it seems you try to treat the containercontrol as a popup.

As for the icons: I use segmented controls with a background picture (I think, not at my Mac atm)

Thanks, Markus, will look through my setup to see if some old segmented control code resides.
The background images are some NSSegmentedControls then? Cocoa delivers a multitude of optical options that seem not to be available for Xojo controls I really do miss – or did I miss them?

Back at my Mac. Sorry, was wrong on the segmented controls. I use a containercontrol with a canvas and some pictures which works nice for my purpose.

For the popup in container controls see the screenshot. Each colour is a container control with a canvas and a popup:

Thanks Markus. Yes. that would‘t fit my needs. Nothing against the built-in segmented control, but I would really be able to use the extended native versions. But wow, it‘s that much to declare and a lot of interdependencies! (Same goes for NSButtons, btw.)

About the casting: when you cast then you tell the compiler “what comes next is what I say it is”, so if you cast like

PopupMenu( ContainerControl ).text

you tell the compiler that the ContainerControl is a popupmenu … which it is clearly not.

The best thing would probably be if you add a bridge, e.g. a property to the ContainerControl that you can access from outside.

So add a property “myPopUp” as PopupMenu to the ContainerControl.

Make sure that myPopUp exists: so In the ContainerControl add a method “Constructor”. Add the code to it “myPopUp = new PopupMenu”

In the Popup on the ContainerControl add in the Open event: “myPopUp = me”

So now from the outside you can simply access ContainerControl1.myPopUp as you would any PopupMenu, for example:

ContainerControl1.myPopUp.addRow “success”

(hope I got that all right)

Thanks again, Markus. I had to revert to an older version because I had maneuvered myself into too many errors. Guess I‘ll start on redesigning the original control rather and check for everything is right step by step.

Been there :wink:

One thing to note: it is easy to forget a bracket “)”, especially with casting, and you might suddenly be shown 4 or 5 errors just because you forgot that single bracket.