68 views
in GUI Development by

Hello,

I would like to change the outlet variable of a ValueDisplay Item from another page.

Let me explain:

 - the project has several pages (Page1, Page2, etc.) used to set cycle parameters, and you can navigate between them. There is a "common" page that displays a work cycle;

- on one page (Page1), there is a ValueDisplay object, and on the same page, a slot method called UpdateSlot with the following code:

 if (Application::Device.ControlVar == 1)
 ValueDisplay.Outlet = ^Property1;
 if (Application::Device.ControlVar == 2)
 ValueDisplay.Outlet = ^Property2;
 if (Application::Device.ControlVar == 3)
 ValueDisplay.Outlet = ^Property3; 
...

- Using different buttons on various pages or external commands, a slot method in the Application::Device class is executed. This slot method assigns a specific value to the ControlVar variable and displays the "common" work cycle page with the PresentDialog command:

rootthis.PresentDialog( new Application::CyclePage, null, null, null, null, null, null, null, null, false ). 

The slot method executed depends on the external button/command, meaning that there are various buttons/commands that execute different slot methods in the Application::Device class, which set the command variable to different values ​​and display different pages. The slot method is called StartCycleX with X being the number of the ControlVar variable.

- Within these Slot Methods, I would like to execute the UpdateSlot slot method of Page1 to update the Outlet of the ValueDisplay object of the same page.

- The new page (CyclePage) is deleted after a while using the DismissDialog command.

I tried inserting the following code into the StartCycleX slots in the Application::Device class, but it didn't work. 

var Application::Page1 dialog = new Application::FirstPage;
signal dialog.UpdateSlot;

or writing:

signal Page1.UpdateSlot; 

In the first case nothing happens, while in the second I get an error directly in the prototyper.

1 Answer

0 votes
by

Hello Nicola,

you're trying to update a ValueDisplay outlet in Page1 from slot methods in Application::Device, but the approaches you tried don't work because:

1. First approach: You create a new instance of Page1, but this is not the same instance that's actually displayed in your GUI. Signaling the new instance has no effect on the visible page.

2. Second approach: Page1 is a class name, not an object instance, so you can't send signals to it directly.

You need a kind of notification between Device and the Page. I would use for this purpose the System Event and System Event Handler.

Step 1: In Device class add a new System Event. Name it appropriately, e.g. ControlVarChangedEvent.

Step 2: In Device class wherever the ControlVar is changed and you want the Pages to be notified about that event, add following line of code (see also: Trigger System Events locally from Chora code):

ControlVarChangedEvent.Trigger( null, false );

Step 3: In all affected Page components, add to each a new System Event Handler.

Step 4: Connect each System Event Handler to the System Event existing in the Device object. See also Connect the Handler with a System Event object). 

Step 5: Connect each System Event handler to the UpdateSlot method existing in the corresponding Page component. For this purpose you assign UpdateSlot to the handler's property OnEvent. (See also Implement the onEvent slot method).

Now, when the Device changes the variable, the system event is broadcasted. The handler in the Page component receives the notification and triggers UpdateSlot method.

I hope it works.

Best regards

Paul Banach

 

by
Hello Paul,

I tried and it works as expected!

Thank you for support.

Embedded Wizard Website | Privacy Policy | Imprint

...