453 views
in Embedded Wizard Studio by

Hi,

I have already studied the https://doc.embedded-wizard.de/implementing-component-interface?v=9.10#5

but I still feel confused.

If I want to do the following function

I have an autoobject,Mode.

In class1 I have 5 objects ( same type, named a.b.c.d.e)

In class2 I can set Mode to true or false.

If Mode == false

    object a and b 's Visible & Enabled should be false

else

   object a and b 's Visible & Enabled should be true

 

Is this function can be implemented by Outlet properties,and how? 

Or is there any better way to do this?

Thanks

Best Regards,

Andy Dong

 

 

 

 

 

1 Answer

0 votes
by
 
Best answer

Hello Andy,

yes, if you use them together with the observers. Let me as first explain the 'low level' approach:

Step 1: Implement a class for the autoobject.

Step 2: Within the class add a property and name it e.g. Mode. Adapt the data type of the property to bool.

Step 3: Edit the OnSet method associated to the property to containf following code:

// The value doesn't change - nothing to do.
if ( pure Mode == value )
  return;

// Remember the property's new value.
pure Mode = value;

// Notify all associated property observers.
notifyobservers ^Mode;

Step 4: Create an autoobject of the class (from Step1). Let's assume the autoobject is named Application::Data.

Step 5: Within your class1 add a new slot method and name it e.g. onModeChanged.

Step 6: Within your class1 implement following code to register an observer to react when the property Mode existing within the autoobject is changed and thereupon signal the slot method onModeChanged. You can execute the code e.g. within the Init method:

attachobserver onModeChanged, ^Application::Data.Mode;

Step 7: Edit the slot method onModeChanged to hide/show the views according to the actual state of the property Mode:

var bool mode = Application::Data.Mode;

a.Visible = mode;
b.Visible = mode;
a.Enabled = mode;
b.Enabled = mode;

Step 8: Within your class2 implement following code to change the value of the property Mode existing in the autoobject:

Application.Data.Mode = true;

... or ...

Application.Data.Mode = false;

This 'low level' view on the implementation is very useful to understand the mechanisms how the objects interact. The autoobject Application::Data serves in this case as a global 'controller' instance. It stores within its property Mode a value true or false. Each time this property is changed, a notificaation is sent to all previously registered observers. This is the case of the class1. By using the attachobserver statement you register a slot method as observer for all notifications associated to the property Mode of the instance Application::Data. Now, when somone else (e.g. from class2) accesses and changes the value of the property Mode, the slot methods in all actually existing instances of class1 are signaled. The methods update accordingly the Visible/Enabled states of the views, etc.

If you understand this mechanism you can implement the second approach. Please take a look at the Gallery Templates folder Device. This folder contains diverse templates intended primarily for the integration and data exchange with the underlying device. These templates, however, can also be used to implement classes to store global settings, data values, etc. used in the application. All GUI components can then access, evaluate and modify these values. The approach leads to the same results as described above. The unique difference is, you need less code to implement. The templates contains already the necessary invocations like attachobserver or notifyobservers. The concrete steps are:

Step 1: Implement a class for the autoobject.

Step 2: Within the class add a property. This time, however, use the template Property from the folder Device! Again name the property e.g. Mode and adapt its data type to bool. More about this special kind of property is found in Device Property

Step 3: Create an autoobject of the class (from Step1). Let's assume the autoobject is named Application::Data.

Step 4: Within your class1 add a new Property Observer from the folder Device. More about this special kind of observer is found in Property Observer.

Step 5: The just added Property Observer comes with its own slot method onEvent. Just open the slot method and implement the code:

var bool mode = Application::Data.Mode;

a.Visible = mode;
b.Visible = mode;
a.Enabled = mode;
b.Enabled = mode;

Step 6: Connect the Property Observer with the property Mode existing in the autoobject.

Step 7: Within your class2 implement following code to change the value of the property Mode existing in the autoobject:

Application.Data.Mode = true;

... or ...

Application.Data.Mode = false;

Does this explanation help you to undertsand the underlying concepts?

Best regards

Paul Banach

by
Hi, Paul Banach

It's really really helpful !

Thank you so much.

Best Regards,

Andy Dong
by

Hi,Paul Banach

one more question

I used the Property from the Device folder and it create a method,UpdateProperty.

What kind of condition happened  that I will need to use this method ?

Because I delete this method my project still worked fine

Thanks

 

Best Regards,

Andy Dong

by

Hello Andy,

the template Property from the Device folder is used usually when you create an interface between GUI and the device. In such case the Property represents a concrete value within the device (e.g. the actually configured voltage in a power supply device, etc.). When the value changes the device can inform the GUI about this by calling the method UpdateProperty()

Since your Property is not intended to reflect a value existing in the device, it is fully correct to delete the method UpdateProperty(). More about this method and its function is explained in the chapter Device Property. Please note the figure at the beginning of the chapter demonstrating the usage of the UpdateXXX() method (XXX corresponds here to the concrete name of the property). See also the section Update Property.

Best regards

Paul Banach

by
Hello Paul Banach,

Thanks for your explanation.

I will study the information.

Best Regards,

Andy Dong

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

...