[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objects with Widgets, Save/Restore

Brent Griffith wrote:
> I am using a handful of home-made objects (thanks to RCK's book) in a
> application with lots of widgets.  I am trying to use SAVE and RESTORE
> to get my objects back to where they were in a previous run of the
> application.  I have it sort of working but would appreciate seeing
> some examples of an "object's restore method".
> For example, is there an elegant way to deal with the widget IDs and
> values?  I am storing widgetIDs in the object for widget_control
> statements, but the newly created widgets generally have different IDs
> than the old Saved-object.  I find myself repeatedly writing the same
> statements for each and every widget that might get its value changed
> -- see example statements below (* and 1 indicate multiplicity).

You might check older postings of mine which comment on this very topic
ad naseum.  The basic idea is to detach those portions of the object
data structure which aren't relevant to a saved version, before saving. 
This requires a bit of organization, but is pretty easy.  Here are a few
messages I found regarding this method:


Here's an example, excerpted from a complicated class of mine:

   ;; Detach the stuff we don't want to save!
   detInfo=self.wInfo & self.wInfo=ptr_new() ;don't save the info
   detMsgList=self.MsgList & self.MsgList=ptr_new() ;or the message list
   ;; Here we detach the data to avoid duplication, if they want it.
   if self.SpaceSaver eq 1b then begin
      detDatas=(*self.DR).DATA  ;or the data
      detTotals=(*self.DR).TOTAL ;or the totals
   endif else self->RestoreAll
   oldchange=self.Changed       ;we want the file written to have
   self.Changed=0b              ;but save the old preference incase we
   catch, serr
   if serr ne 0 then begin      ;it failed!
      self.wInfo=detInfo        ;reattach them
      if self.SpaceSaver eq 1b then begin ;reconnect the data
      self.Changed=oldchange    ;reassign our old changed status
      wmessage,PARENT_GROUP=pg, $
       'Error Saving to File: '+pname
   ;; Reattach 
   if self.SpaceSaver eq 1b then begin 

Notice the error handling, especially.  You don't want to lose your
running widget hierarchy if the save fails.  I basically remove the
entire widget info structure (which is nicely organized under a single
pointer) among a few other things, and then on restoration, I can
rebuild the widgets there again... something like:

   ;; make the info structure if we need it.
   if NOT ptr_valid(self.wInfo) then begin

You probably get the point.

Good luck,