Proper or accepted way to address a Parent

Let me appologize ahead of time for using incorrect termionology in this question.

If, for example, I drag a WebContainer to my project and put a button in it that will be acting on something in it’s parent. How do I write that code so that it will work in any parent into which I put an instance of the container

I have a test project where I have a MapViewer in the WebPage. To see how this might work I created a Container that I called cntMapController which has a text field and a button in the button I put…

Dim location as New WebMapLocation location.APIKey ="AIzaSyAb-_cnEvKxxxwaq_14ZCo_xxxx-qA" location.Address = tfLocation.text WebPage1.MapViewer1.GoToLocation(location)

If I drag cntMapController onto the WebPage it creates an instance of the container cntMapController1. And that will work fine, but I don’t want to use WebPage1.MapViewer1.GoToLocation(location). I expected to find some means to address the contents of the parent of the instance of the container without hard coding the parent. Anything I try throws an item not found error on the map viewer.

Asking for a little bit of eductation on how or what is the proper way to have an instance of a container address it’s parent objects.



What about self.Parent ?

self.parent.MapViewer1.GoToLocation(location) throws a type error during code assembly. I would have thought self.parent.parent would be required as isn’t the parent of the button the container? But, alas self.parent.parent also throws the type error.

The problem I think is getting past the error checking before the app is run.

Just noticed that the type error says…

Type “WebView” has no member named “MapViewer1”

Again, I used the wrong terminology. Not a type error, but noticed that the view it cannot find the MapViewer1 in is of type WebView. Is the entire site the WebView?

Self is your subclass instance (cntMapController1). In other words, the WebContainer if I read your code correctly.

Self.Parent should be the WebPage the webContainer was instantiated on (WebPage1).

You should be able to debug that with something like this in a button on the WebContainer:

System.Debuglog self.Name System.Debuglog

Another way to handle this would be to create an Event Definition on the Container, and in the Event Definition include the needed parameters. Then have the code in the Action Event of the Button in the Container raise the Event, along with the relevant values/parameters.

By using this approach, when you create an instance of the Container on a WebPage, the WebPage can add an Event Handler for the Event Definition of the Container and deal with the information that is “communicated” to it.

In some ways, this feels like an “inside out” way of approaching things, but it ends up giving you a lot of flexibility. The Container doesn’t need to know the specifics of the WebPage that contains it. It merely raises the event to communicate the information.

With respect.


@Michel Bujardet understand what you said wrt self, I confirmed it for myself by putting self.parent.namein a msgBox displayed when I clicked the button.

The problem is that if I write self.parent.MapViewer1 instead of WebPage1.MapViewer1 in cntMapController the debugger throws the error “Type WebView has no member MapViewer1” before the web app runs. This makes sense as cntMapController in fact does not have MapViewer1 in it, WebPage1 does.

Thus my question.

@Markus Winter Ha! took me a while.

@Arthur Couture I am not familiar with Event Definitions so not sure how to do what you are suggesting. I will take a look in the docs to see if I can figure it out and try your suggestion.

It sure would be a lot easier if there was someway to write it so that the debugger doesn’t choke on a reference to a potential parent when running as an instance of itself.

The problem is that the container has no idea what kind of object Parent is, so it defaults to the generic WebView. You might try code like

if self.parent ISA WebPage1 then

@Tim thanks, but might just as well not use the ISA if statement and call WebPage1.MapViewer1.GoToLocation(location). WebPage1 is still hard coded. I wanted to just use self.parent without having to hard code the parent name.

Guess there is no way to do what I am looking for. Probably not possible to assemble the code without a valid address, but It would be nice if ISA ignored the contained line of code during assembly so the app could run and only make the contained call at run time if the instance of the conatiner is in fact in a WebPage. “If self.parent ISA WebPage” is also valid and works at run time no matter what the WebPage is named. That would allow the container to be dropped in any web page. But then again, the MapViewer poses a similar issue. :frowning:

Anyway, not a big deal. Just trying to educate myself. Thanks for your replies.

Then the appropriate mechanism is an Event. You add an Event Definition to the Container and implement that event in Webpage1.

@Tim Hare and @Arthur Couture I am sorry I did not pursue your suggestion wrt using an event. Just got done learning how to define and use an event in the container. I got it to work and learned something new that does exactly what I was looking for.

I don’t think that this approach is in any way “inside out”. The container becomes completely reusable. without putting any constraints or requirements on the parent of the instance. Perfect.

Thanks again,