357 views
in Getting started by
Hello,

I've just started exploring and using embedded wizard and I don't understand how I can access variables of a parent from a child.

Here's my example : I have a component main_screen that's positioned in the application window by drag and drop (hence will exist forever in memory, no matter if displayed or not). In that main_screen, I've a rectangle on top of all other widgets whose purpose is to "deactivative the screen". By clicking a button on the main_screen, I display another dialog (modal), a numpad and I activate the visibility of the rectangle on top of everything. Simple.

Now, I'd like from the numpad dialog to turn off the visibility of the rectangle of the main_screen. Fundamentally, I know how to do it by connecting properties for instance but I find it cumbersome and I'd like to be able to do in a method of the numpad something like :

this.Owner.Rectangle.Visibility = false;

Clean and simple...

But it doesn't work...I was expecting to be able to have access to the widgets of the main_screen by accessing the parent of my numpad dialog (that is, the main screen). What am I missing ? How can I circumvent this?

Thanks in advance.

1 Answer

+1 vote
by
 
Best answer

Hi,

the approach to access members of the Owner is the right way. The problem here, Owner is declarared with the type of the most generic component class Core::Group. Since Chora is type restrictive, you can access the members of an instance only if it is known which type it has. Thus, you will need to apply the type cast operator on Owner in order to test whether the Owner is really of the desired component type. For example, assuming the Owner is a component Example::SomeDialog, then to access the Rectangle member of this component do following:

// First test, whether 'Owner' is actually an instance of 'Example::SomeDialog'.
// Then, if successful, access the member of the instance.
if ((Example::SomeDialog)Owner != null )
  ((Example::SomeDialog)Owner).Rectangle.Visible = false;

You can also do following:

// First try to cast the 'Owner' to the expected component type
var Example::SomeDialog dialog = (Example::SomeDialog)Owner;

// If successful, access the member of the instance.
if ( dialog != null )
  dialog.Rectangle.Visible = false;

Best regards

Paul Banach 

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...