Sharing data between GUIs by application data of root?

1 次查看(过去 30 天)
Hi,
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!
Staffan

采纳的回答

Jan
Jan 2011-4-15
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');
otherwise
error(...)
end
Then setting a single breakpoint inside this function let you observe any change of the "global" variable.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by