Access window objects from an event

Description

Access other objects in event calls

What MCU/Processor/Board and compiler are you using?

ESP32 on ESP-IDF 4.2 +littleVGL 6.0

What do you want to achieve?

a setting windows with a SAVE button. When clic on SAVE, … run saving function…
but local variable in the event is only related to SAVE button, NOT the settings objects. Then event cannot get objects (settings) values. then cannot save.

What have you tried so far?

i tried to put some settings objects of my win in static “global” variable : it work (can get value from click-saveButton-event), but did i really have to put ALL my objects in global variables to access it from events ??? seems to be not an ideal way to do…

Thanks for your help !

Unfortunately, that’s the simplest method I can think of for C.

another idea is to make a loop test in the “building widows function” (there all objets are local variable, then accessible) over a static “status” variable. … if (status ==1) { disable save button & make save actions }

Then, change global “status” variable into clic button event…

probably cleaner, cause all object stay local, then will be really free from memory when destroy parent object. otherwise, if all is global variable, it continue to consume this memory…

It’s probably a VERY common problem… How do you do this kind of actions ?

An alternative approach might be to store object references in an allocated structure and point the user_data pointer of the parent object to that.

2 Likes