686 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 - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...