Can't access this variable

I’m developing a new control for my app that will have instances of a couple of DesktopContainers inside another DesktopContainer. I’ve made a small test project to illustrate my problem, see below:

TestContainer has an instance of InsideContainer within it, and also a property, TestProperty. Now, within InsideContainer there is a button Button1, whose Pressed event is shown.

I want that button’s Pressed event to be able to set TestProperty to some value, as shown, but whatever I do I’m getting compilation errors such as “does not exist” or similar. I’ve tried prefixing it with Self, or Me, or Parent, but none works.

What am I missing?

TestProperty belongs to TestContainer so InsideContainer cannot access it.

My suggestion would be:
• Add a custom event definition to InsideContainer.
• Use RaiseEvent in the button event to invoke your custom event
• Implement your event definition in the TestContainer.InsideContainer instance and put your code there.

1 Like

alternate dependency injection.

the event that kevin suggested is somehow a method
WhereAmI() which return TestContainer

if you want it neutral you can also use an interface.

OK guys thanks. IOW, I shouldn’t be doing it quite that way. So with a certain rejigging it’s OK. In terms of the example I posted, I just promote the contents of InsideContainer to TestContainer, and do away with InsideContainer.

The integer is a property of the parent’s parent.

TestContainer(Parent.parent).testproperty = 6

1 Like

At run time you can have many instances of testcontainer, you cant expect the compiler guesses wich one you are intended to address, (assuming the variable were in the scope)

You need a reference (property) on the InsideContainer pointing to the TestContainer so you can do that, InsideContainer.TestcontainerReference.Testproperty. But The answer by kevin g is the Best practice one.

Doesn’t work that way. The control (in this case InstanceContainer) does not have “free” access to its parent properties. Define an event on InstanceContainer, have the button press fire it, and then implement the new event on your instance of InstanceContainer on TestContainer.

Edit: Ug, for some reason none of the replies loaded, so I didn’t see that this got answered already. I’ll leave the message up for posterity I guess.