Container Control calling a Window Method

On a Window, I have a Container Control that includes some buttons. How can I have the Container Control button run a Method on the Window?

From all the forum searching I did, it sounds like I need to raise an event. Does that sound right? How do I do that?

You could call:




from the PushButton’s Action event.

[quote=145675:@Tim Jones]You could call:



You could but explicit references to parent objects are really not considered good form for portability reasons. If the container control would never be used anywhere else, then I suppose you could.

[quote=145675:@Tim Jones]


from the PushButton’s Action event.[/quote]

No, you can’t. Well, you can but it won’t do what he wants. Because “self” for the pushbutton is the container control not the window and he wants to run a method in the window.

I would implement an event definition and raise that event in the push button’s action event. This is really the best way, IMHO, because now you are running a method of the window in the window object itself. Yes, the container control is in the window, but I like the event way better.

Jon, could you be so kind to explain how to implement the events? What do I put where?

In the navigator on the left hand side of your window, right click in the container control object and select “Add To” and then select “Event Definition” from the list. You need to do this on the container control subclass you are making and NOT to the instance that is on your window.

Now, name that event definition whatever you want: HalsUpdateMethod in my case here. Name it just like any other method including any parameters, return values, etc.

The in your button’s action event add:

RaiseEvent HalsUpdateMethod

Plus any other code you want that is part of the container control only.

Then in your window where you have the instance of your container control, right click on it and select to add an event handler. Choose your new event handler, HalsUpdateMethod from the list. Now in there put your call to your method in the window:


There you go. To me, this is really the way to do it.

1 Like


Thank you so much. It worked perfectly.

I’m going to see if there’s a session on classes at XDC. It’s so hard to figure this kind of stuff out, but when explained, it’s so easy.

[quote=145691:@Hal Gumbert]Jon,

Thank you so much. It worked perfectly.

I’m going to see if there’s a session on classes at XDC. It’s so hard to figure this kind of stuff out, but when explained, it’s so easy.[/quote]

You are welcome. It took me forever to get my head around subclasses. The first few releases of my app had no subclasses but lots of explicit window calls. It worked. But then I discovered subclassing and what it could do and how you can make things portable. I’ve got a long, long way to go and I learn more every day. There’s a lot of guys here that are far better coders than I am. I just try to walk in their footsteps! :slight_smile:

That’s exactly where I’m at… I’ve been using explicit calls and its killing me. Subclassing is one step back and five steps forward.

I’m going to touch on encapsulation during my XDC session, but from a little different angle. I may be able to beef that up a bit. Or just hit me up after hours if the light hasn’t gone on by then. It’s one of those things that is very hazy until one day you have that Aha! moment and it all becomes clear.