Effacer les filtres
Effacer les filtres

Sharing data between GUIs by application data of root?

1 vue (au cours des 30 derniers jours)
Staffan le 15 Avr 2011
I use a couple of GUIs and use setappdata(hGUI1, 'data', data) to store data. To share the handles of one GUI to all other GUIs i use setappdata(0, 'hGUI1', hGUI1).
But, to use the shared data in lets say GUI2, GUI1 needs to be open. Since every GUI use the same data, I want every GUI to work independent from the other GUIs. My idea is to directly use the application data of the root: settapdata(0, 'data', data) and thus make it accessible for every GUI.
But... Is this good idea or does it cause problems I dont see at the moment? Will this method still work with compiled versions of the GUIs? Is there a better way to solve this?
Would appreciate any help or comment - thanks!

Réponse acceptée

Jan le 15 Avr 2011
Storing values in the ROOTs ApplicationData or UserData is valid - as long as you do not make any mistakes. Sharing a single object is equivalent to using a GLOBAL variable. As long as you care for correct writing, especially by using a unique name for the variables, everything wents fine.
But is any problems occur, debugging will be much harder. An additional data handling layer can be very helpful then: Create a function, which is responsible for all read and writre operations to these data:
function Data = DataHandler(Command, Data)
switch Command
case 'put'
setappdata(0, 'DataHandler', Data);
case 'get'
Data = getappdata(0, 'DataHandler');
Then setting a single breakpoint inside this function let you observe any change of the "global" variable.

Plus de réponses (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by