Calling parent methods from other class

I have a question regarding how to work on a parent class several levels up from another class which has controls generating an event.

To make this clear, here’s a simplified example of my question:

TheDataObject AS MyData

Event Handlers:
Open: TheDataObject = New MyData

Class MyData
A: Integer
ModifyData > A = A+1

Window A (Super: Window)
MyCanvas As SpecificCanvas

SpecificCanvas (Super: Canvas)
BoxArray As Myboxes(0) // Array of a container class MyBoxes which contains controls

MyBoxes (Super: ContainerControl)
Button1 As BevelButton
Button1.Action: TheDataObject.ModifyData
Button2 As BevelButton

As you can see in this simplified example, when the user clicks on the Button1 of one of the boxes displayed on the
canvas, I want to make a change to some data (Increment property A within the instance of the MyData class).

I have used a Global property “TheDataObject” to be able to access the MyData class from the Button1 Action event,
but I’m sure there’s a better way of doing this (to avoid using a global variable in the definition of the boxes class).

I hope the simplified example is clear enough to express the issue.

Any ideas are welcome.

If you’re concerned about encapsulation (not using global references in the class), you should add an event to the MyBoxes containercontrol that the window can implement.

MyBoxes (Super: ContainerControl)
Button1 As BevelButton
Button1.Action: ModifyData
Button2 As BevelButton

If you add the containers to the window in the IDE, then you can fill out the event code directly. If you add the containers in code, then use AddHandler to tie the event to a window method that implements the event.

Thanks Tim for your answer. One point is still unclear:

I now added an event (Myevent) to my container class using an event definition and from the Button1.Action event, I just use RaiseEvent.Myevent and that’s fine, however, when I’m in my window class above, when I do the following in one of the methods:

aBox = New MyBoxes
AddHandler aBox.Myevent, AddressOf DataMethod (DataMethod being a method added to the window class to manage data)

I obtain an error message (expected delegate.delegate(Mybox.Mybox), but got delegate Delegate

What is wrong in the syntax I’m using in the first part of the AddHandler?

Found the solution by looking at other help requests. In the definition of my method in the window class, I forgot to add the parameter of the class sending the message, e.g.:

DataMethod (Sender As MyBoxes)

After adding this, it now works fine