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