home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / www / afc / afc-dir / stringnode_examples.lha / Examples / Push_Pop_Example.e < prev    next >
Encoding:
Text File  |  1997-09-09  |  1.6 KB  |  62 lines

  1. /*
  2. ** StringNode Example-3
  3. **
  4. ** add(), item(), push() AND pop() methods.
  5. **
  6. ** (C)Copyright 1996/97 Amiga Foundation Classes
  7. **
  8. ** See: http://www.intercom.it/~fsoft/afc.html
  9. **
  10. **      FOR more info about AFC AND more modules
  11. */
  12.  
  13. MODULE 'afc/StringNode',   -> Our MAGIC MODULE
  14.        'afc/explain_exception'
  15.  
  16. PROC main()  HANDLE
  17.   DEF n:PTR TO stringnode      -> This is our OBJECT instance
  18.  
  19.   NEW n.stringnode()           -> OBJECT initialization
  20.  
  21.   n.add('Zorro')              -> Here we add some items...
  22.   n.add('Batman')
  23.   n.add('Superman')
  24.   n.add('Gold Drake')
  25.   n.add('Mandrake')
  26.   n.add('MOMMY')
  27.  
  28.   shwall(n)                   -> Here we see them
  29.  
  30.   n.item(2)                   -> Let's pos us on item 2
  31.   WriteF('Current:\s\n', n.obj())
  32.  
  33.   n.push()                    -> Here we memorize our position
  34.  
  35.   n.item(5)                   -> Let's pos us on item 5
  36.   WriteF('Current:\s\n', n.obj())
  37.  
  38.   n.pop()                     -> Here we RETURN TO item 2!!!
  39.   WriteF('Current:\s\n', n.obj())
  40.  
  41.   n.item(99)                  -> What??!?!?! This item DOES NOT EXISTS!!!
  42.   WriteF('Current:\s\n', n.obj())    -> Is it safe enought??
  43.  
  44. EXCEPT DO
  45.   explain_exception()
  46.   END n                       -> Remember ALWAYS TO end an OBJECT
  47.   CleanUp(0)
  48. ENDPROC
  49.  
  50. PROC shwall(n:PTR TO stringnode)
  51.   WriteF('------- \d ----------\n', n.numitems())
  52.  
  53.   IF n.first()                      -> Here we go TO the first node item
  54.     REPEAT
  55.       WriteF('Node:\s\n', n.obj()) -> Node STRING...
  56.     UNTIL n.succ() = FALSE          -> LOOP UNTIL the end
  57.   ELSE
  58.     WriteF('No Nodes in LIST...\n')
  59.   ENDIF
  60. ENDPROC
  61.  
  62.