home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / www / afc / afc-dir / iffparser_examples.lha / Examples / IFFParser_Example2.e < prev   
Text File  |  1997-09-09  |  2KB  |  59 lines

  1. /*
  2. ** IFFParser_oo Example 2
  3. **
  4. ** This code shows how to load/save
  5. ** a very simple IFF preferences file.
  6. **
  7. ** (C)Copyright 1997 Amiga Foundation Classes.
  8. **
  9. ** This code is placed in the PD
  10. ** and may be intended for explanation only.
  11. **
  12. */
  13.  
  14. MODULE 'afc/iffparser',        -> Our MAGIC MODULE!
  15.        'afc/explain_exception'
  16.  
  17. OBJECT testprefs        -> This is our little prefs structure
  18.   x
  19.   y
  20.   w
  21.   h
  22. ENDOBJECT
  23.  
  24. PROC main() HANDLE
  25.   DEF iff:PTR TO iffparser      -> This is our object instance
  26.   DEF t:testprefs               -> Here there is our prefs var
  27.   DEF n=NIL:PTR TO testprefs    -> And just a ptr to it
  28.  
  29.   NEW iff.iffparser()           -> First of all we have to INIT the object
  30.  
  31.   t.x := 1                      -> Here we set some dummy values inside
  32.   t.y := 2                      -> Our prefs var
  33.   t.w := 3
  34.   t.h := 4
  35.  
  36.   iff.save('ENV:Test.prefs')         -> Here we begin to write our prefs file
  37.   iff.createchunk("PREF","FORM")     -> This is the FORM chunk
  38.     iff.createchunk("PREF","PRHD")   -> And inside this one
  39.     iff.writechunk(t, SIZEOF testprefs) -> We will store the prefs var
  40.     iff.closechunk()                 -> And close it
  41.   iff.closechunk()                   -> Here we close the FORM chunk
  42.   iff.close()                        -> End of IFF save session.
  43.  
  44.   iff.load('ENV:Test.prefs')        -> Now we have to try to read it again!
  45.   iff.setscan("PREF","PRHD")        -> We look for PRHD inside PREF
  46.   iff.exit("PREF","FORM")           -> The search will stop at the end of FORM
  47.   iff.scan()                        -> Scan!
  48.   IF (n:=iff.first("PREF","PRHD"))  -> If there is at least one item...
  49.     WriteF('x:\d - y:\d\nw:\d - h:\d\n', n.x, n.y, n.w, n.h)  -> Show it!
  50.   ENDIF
  51.   iff.close()                       -> End of IFF load session
  52.  
  53. EXCEPT DO
  54.   explain_exception()                -> Just to know exception name
  55.   WriteF('Cleaning Up... \n')
  56.   END iff                           -> ALWAYS END THE OBJECT BEFORE EXITING!!!
  57.   CleanUp(0)
  58. ENDPROC
  59.