Using the "click" Command on non-visible components

I have a Log page which uses the Data object to store various events in my application.
On the Log page I have added a global string variable which holds the line event details to be logged and a hidden Hotspot object which, in its touch event, adds a timestamp to the event line and inserts the result into the Data object. See below:

// Log_Line contains log entry in the form Type^Message
// Build up a time stamp in s_logtmp
// Build Date in the form DD/MM/YY
covx gDy,s_logtmp.txt,2,0
covx gMnt,s_logtmp2.txt,2,0
covx gYr,s_logtmp2.txt,2,0
s_logtmp.txt+=" "
// Build Time in the form HH:MM
covx gHr,s_logtmp2.txt,2,0
covx gMn,s_logtmp2.txt,2,0
// Create full record in s_logtmp in the form
// DD/MM/YY HH:MM^Type^Message
// Add entry to Data file
// Update the Record count and max value
covx data0.qty,RecCnt.txt,0,0
covx data0.maxval,s_logtmp.txt,0,0

This works fine while the Log page is the active page but if I try and run the click event while on another page in the application I get an invalid component error.

click Log.Update,0 // results in an invalid component

How can I add items to the Data object without having the data object currently visible. I have made the Log page, Update object and Log_Line objects Global but I still get Component Invalid error.

The example in the Nextion Blog assumes every thing is running on the same page but for all real world applications the it has to be possible to add items to a Data object behind the scenes.

John Barrat

While variables and component attributes (which are like variables) can be global, event code (as the Touch Press Event handler for your click action) is always local. The page containing the code which shall be executed has to be active in the memory. That is why the click command allows no page prefixing since it can always only act on components on the current page, and throws that compiler error.

I am now adding the above code to each screen that needs to update the Data object…

It might be - I’m not sure - that the insert method of the data record component requires also that the containing page is loaded.
Worst case scenario is that you would have to duplicate the data record component on each page, too, but let’s hope for the best!