Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Passing handles between GUIs via a loaded file
Date: Mon, 6 Oct 2008 09:33:59 -0400
Organization: The MathWorks, Inc.
Lines: 46
Message-ID: <gcd447$qmp$1@fred.mathworks.com>
References: <gccc79$d4l$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1223300039 27353 144.212.105.187 (6 Oct 2008 13:33:59 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 6 Oct 2008 13:33:59 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:493814



"William " <w_king10@yahoo.com> wrote in message 
news:gccc79$d4l$1@fred.mathworks.com...
> Hi,
>
> I have a GUI with pulldown menus and editable text boxes.  I am trying  to 
> save the configuration of all the editable text boxes and pulldown menus 
> to a file that can be loaded the next time the user wants to use the GUI.
>
> I can run the GUI properly if I start from scratch(All of the handles 
> operate normally).  The problem is, when I rerun the GUI and load in the 
> configuration file, I get an 'Invalid handle object' error.  Does anyone 
> know a way to do this?
>
> Currently, I am saving the handles structure from the previously open GUI 
> into the configuration file.  I then reopen the GUI and load in the saved 
> configuration file.  When the file is loaded, I am copying over the 
> handles structure from the previously opened GUI.  I noticed that some of 
> the numbers change slightly between the two handles (i.e. checkbox3 goes 
> from 320.0040 to 320.0039).  Could this be causing the problem?

I don't believe we state anywhere in the documentation that when a Handle 
Graphics object is saved to a FIG-file and reloaded its handle will remain 
the same.  Therefore I don't think you should make that assumption. 
Instead, I'd key off the Tag property of the objects -- save the appropriate 
data in a struct, then store those structs as fields of a main struct, with 
the Tag of the object being the fieldname in the main struct.

For instance, if the main struct is saveddata, then saveddata.Pushbutton1 
would be a struct containing the saved data for the object whose Tag is 
Pushbutton1.

To restore the state, take advantage of the fact that this two-input form of 
SET works:

    SET(H,a) where a is a structure whose field names are object
    property names, sets the properties named in each field name
    with the values contained in the structure.

set(handles.Pushbutton1, saveddata.Pushbutton1)

-- 
Steve Lord
slord@mathworks.com