home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / System / ScalosPrefs / examples / Blitz / loadsave.bb2 < prev    next >
Text File  |  2000-08-23  |  2KB  |  64 lines

  1. ; Simple example of loading and saving preference files
  2.  
  3. INCDIR "include:"
  4. XINCLUDE "scalos/preferences.bb2"
  5.  
  6. ; some strings
  7. prefname$ = "Example"           ; Name to refer to PrefsHandle with
  8. preffile$ = "example.prefs"     ; filename to save prefs as (does not need to be the same as the name for the prefs handle)
  9.  
  10. ; Temporary memory for when we read from preferences
  11. Dim temp.b(256)
  12.  
  13.  
  14. ; First of all we need to allocate a PrefsHandle by name
  15. ; (There is no specific type for a PrefsHandle, as long as it is a long or a pointer)
  16. *prefhandle.l = AllocPrefsHandle_(&prefname$)
  17. If *prefhandle
  18.     NPrint "PrefsHandle successfully allocated"
  19.  
  20.     ReadPrefsHandle_ *prefhandle, &preffile$
  21.  
  22.     ; We need an ID and Tag value to refer to a specific preference with
  23.     ; so we create that here (or you could just use them in the library calls)
  24.     ; Remember that the ID must be a long created from 4 ASCII characters
  25.     ; and the Tag cannot be 0
  26.     ID.l = Cvl("MAIN")
  27.     Tag.l = 1
  28.  
  29.  
  30.     ; Use FindPreferences_ to check that the item has been stored
  31.     *prefstruct.PrefsStruct = FindPreferences_(*prefhandle, ID, Tag)
  32.     If *prefstruct
  33.         NPrint "Preference data found!"
  34.  
  35.         ; And finally, just to show that the preference data was stored,
  36.         ; we use GetPreferences_ to retrieve the data from memory
  37.         datasize.l = GetPreferences_(*prefhandle, ID, Tag, &temp(0), 256)
  38.         NPrint "Contents of pref data:"
  39.         NPrint Peek$(&temp(0))
  40.     End If
  41.  
  42.  
  43.     ; now we want to set a new value for it
  44.     NPrint "Please enter new string for preference (blank string to not do anything)"
  45.     prefdata$ = Edit$(256)
  46.     If prefdata$<>""
  47.         SetPreferences_ *prefhandle, ID, Tag, &prefdata$, Len(prefdata$)+1
  48.  
  49.         ; And save the preferences out again. run this program again if you
  50.         ; want to check the changes
  51.         WritePrefsHandle_ *prefhandle,preffile$
  52.     End If
  53.  
  54.     ; Finally we free the prefs handle
  55.     FreePrefsHandle_ *prefhandle
  56. End If
  57.  
  58. NPrint "Press LMB+RMB to quit"
  59. While Joyb(0)<>3
  60.     Delay_ 1
  61. Wend
  62. End
  63.  
  64.