save_object

  how to such out an objects properties in order to save them and restore the object later to its current state
oop save/restore properties




  Saving an object for later use
At 23:49 22/06/99 -0300, you wrote:
>Hi, lingoists
>I have to make a book with 10 pages, so I thought it could be done using
>OOP. The page has some properties, like its type (1, 2 or 3 images, field's
>size, field's placement, etc.), its images, and the text inside the field.
>All these properties must be saved in an external castLib, in order to be
>retrieved later, after quiting the application. But how can I store and
>save an object as a text or something? 
>Well, the codes are quite simple yet, but here they are.
>
>--parent script
>property myType,myField,myText,mySprite,myImage
>
>on new me, type, field, text, thisSprite, image
>  set myType = type
>  set myField= field
>  set myText= text
>  set mySprite= thisSprite
>  set myImage= image
>  pageMaker
>  return me
>end
>
>on pageMaker
>  go myType
>  set the text of field myField to the text of field myText
>  set the member of sprite mySprite to myImage
>end 
>--end of parent script
>
>
>--button script that creates the object
>on mouseUp me
>  global pg1
>  set pg1 = new(script "pageMaker","type 1","part a","part c",2,"balls")
>end
>--end of button script that creates the object
>
>So, the deal is to save the page created with the button script, where
>"type 1" is a frameLabel, "part a" is a text field, "part c" is a text
>field, 2 is the sprite number where is a dummy bitmap to be replaced by the
>member "balls".
>Any help would be veeery welcome.
>TIA,
>Antonio
>
>

Antonio, 

this is not a turnkey solution but as an element of what you try to
accomplish here's a handler which packs all the property/value pairs of an
object into a single property list.
The next step would be to make a string from that list, store it in a field
(or as scripttext or fileIO or via postnettext to a cgi or...) and later,
when you want to recreate the object, you make a list from that string
using value() and reset the object properties.

on condense me
  -- return a propList of all property/value pairs of an object
  if objectP(me) then
    dLp = [:]
    cnt = count(me)
    repeat with i=1 to cnt
      dProp = me.getPropat (i)
      dVal = me.getaprop(dProp)
      dLp.addProp(dProp,dVal)
    end repeat
    return dLp
  end if 
end 

on restoreProperties me,dLp
  -- restore the object properties from a property list
  if dLp.ilk <> #proplist then return #missing_data
  
  cnt = dLp.count
  repeat with i = 1 to cnt
    dProp = dLp.getPropAt(i)
    dVal  = dLp.getat(i)
    me.setAprop(dProp,dVal)
  end repeat
end

This approach will choke if a property's value is 
- an object reference (or #picture, #media etc)
- VOID
- a string containing nested quotes ("he said "oops"")




Best regards

Daniel Plaenitz

Home shock + cgi Bits 'n pieces Director Lingo Shocklets Contact










pageID=l_save_object