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

  1. ; Simple example of single data items per tag
  2.  
  3. INCDIR "include:"
  4. XINCLUDE "scalos/preferences.bb2"
  5.  
  6. prefname$ = "Example"   ; Name to refer to PrefsHandle with
  7.  
  8.  
  9. ; First of all we need to allocate a PrefsHandle by name
  10. ; (There is no specific type for a PrefsHandle, as long as it is a long or a pointer)
  11. *prefhandle.l = AllocPrefsHandle_(&prefname$)
  12. If *prefhandle
  13.     NPrint "PrefsHandle successfully allocated"
  14.  
  15.     ; We need an ID and Tag value to refer to a specific preference with
  16.     ; so we create that here (or you could just use them in the library calls)
  17.     ; Remember that the ID must be a long created from 4 ASCII characters
  18.     ; and the Tag cannot be 0
  19.     ID.l = Cvl("MAIN")
  20.     Tag.l = 1
  21.  
  22.     ; The data we want to store in this preference item is defined now
  23.     prefdata$ = "This is some example preference data"
  24.  
  25.     ; Store the preference data in the prefs handle, under the ID and Tag
  26.     ; The reason we pass a length of Len()+1 is so that the NULL terminator
  27.     ; for the string will be stored as well
  28.     SetPreferences_ *prefhandle, ID, Tag, &prefdata$, Len(prefdata$)+1
  29.  
  30.  
  31.     ; Use FindPreferences_ to check that the item has been stored
  32.     *prefstruct.PrefsStruct = FindPreferences_(*prefhandle, ID, Tag)
  33.     If *prefstruct
  34.         NPrint "Preference data found!"
  35.         NPrint "Size of string stored = ",Len(prefdata$)+1
  36.         NPrint "Size of pref data     = ",*prefstruct\ps_Size
  37.  
  38.         ; And finally, just to show that the preference data was stored,
  39.         ; we use GetPreferences_ to retrieve the data from memory
  40.  
  41.         ; Create some memory space to store the returned data
  42.         Dim temp.b(256)
  43.         datasize.l = GetPreferences_(*prefhandle, ID, Tag, &temp(0), 256)
  44.  
  45.         NPrint "Bytes retrieved from pref data = ",datasize
  46.         If datasize > 0
  47.             NPrint "Contents of pref data:"
  48.             NPrint Peek$(&temp(0))
  49.         End If
  50.     Else
  51.         NPrint "Preference data was not stored!"
  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.