226 views
in GUI Development by

Hello,

I have a problem in updating a vertical list.

I have created a vertical list to show some "cycle phases" and the time associated to each phase.

So I have created a class for the list item in the Application unit which contains a property name and a propery value.

When the page loads, the list displays as follows:

The goal is for the list to display the current phase and the remaining time in black, then a countdown to zero for each phase. As suggested in the guides, I set up two arrays to display the name (PhaseNamesArray) and the remaining time of the phase (PhaseTimesArray). So the method called when the list loads is as follows:

//IntemNo indica elemento attuale della lista (da 0 a numero di elementi lista)
var int32       itemNo   = PhaseVerticalList.Item;

//Definisco la variabile con il tipo di elemeto della lista
var Application::CyclePhaseItem itemView = (Application::CyclePhaseItem)PhaseVerticalList.View;

// The implementation of this slot method does not match the item class
// specified in the associated list component. Or the slot method is not
// called in context of the OnLoadItem list operation. 
if ( itemView == null )
  return;

itemView.Name   = PhaseNamesArray[itemNo];                  //Nomi dati da array (con indice calcolato sopra)
itemView.Time   = PhaseTimesArray[itemNo];

//Imposto altezza elementi in base al parametro ItemHeight
itemView.Bounds.size = PhaseVerticalList.ViewSize;

Set up a 100 ms timer which each time calls the following slot method:

var int32 SelectedItem = PhaseVerticalList.SelectedItem;

//Decremento tempo ciclo e array fase
Application::Device.CurrentCycleTime--;
PhaseTimesArray[SelectedItem] = PhaseTimesArray[SelectedItem] - 1;

//Aggiorno valore oggetto su lista
PhaseVerticalList.InvalidateItems(SelectedItem, SelectedItem);

if (Application::Device.CurrentCycleTime <= 0)
{
  PhaseVerticalList.SelectedItem = PhaseVerticalList.SelectedItem + 1;
  Application::Device.CurrentCycleTime = PhaseTimesArray[SelectedItem];
}

notifyobservers ^Application::Device.CurrentCycleTime;

The problem is that even though I changed the value of the PhaseTimesArray array and called the InvalidateItems method to update the modified item, it does not update and I don't understand why.

Note: The Application::Device.CurrentCycleTime value is used to display the current phase cell timer larger. The page, still sketchy, looks like this:

1 Answer

0 votes
by

Hello Nicola,

I suppose the issue is related to the lifetime of the autoobject Application::Device. If not used, the autoobject is released and the changes you made in its CurrentCycleTime variable are reset. Try to prevent the autoobject from being released by assigning in a variable a reference to this object as explained in the section Lifetime of an autoobject.

I hope it helps you further.

Best regards

Paul Banach

by

Hello Paul,

thank you for the answer. I have understood what you mean, but practically, I don't know how to declare a "global" variable in the code, since in the section Lifetime of an autoobject the declaration is written in the code, and I think I can't add code or functions in the Application component. So can you please explain better how to do it?

Anyway, I checked and the variable CurrentCycleTime is not reset (I added a trace command on the method that decreases the variable and it is decreased correctly).

The main information is that maybe I have found the issue! Maybe I forgot this code line in the OnSetTime method in the CyclePhaseItem class:

ValueDisplay.CurrentValue = value;

Here a screen of the CyclePhaseItem class:

Even if i linked the DisplayValue outlet with the property Time (as shown above), this was enough when creating the list, but not for updating the variable.

One more question on the OnSetTime method: I see that the DisplayValue gets updated whether I write this code:

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

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

ValueDisplay.CurrentValue = value;

or this:

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

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

notifyobservers ^Time;

Which is better?

by
Hello Nicola,

in the first case, the modification of the property Time is directly relayed to the ValueDisplay by assigning the new value to this object. In the second case, the ValueDisplay object itself is connected to the property Time via its Outlet. When the property Time is modified, a notification is broadcast to all connected Outlets. This also affects the ValueDisplay since it is connected to Time. The results are thus same. The first approach, however, is more efficient.

Best regards

Paul Banach
by
Thanks for the explanation! I will use first approach.

Best regrads.

Nicola

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

...