home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 13
/
AACD13.ISO
/
AACD
/
System
/
ScalosPrefs
/
examples
/
Blitz
/
single.bb2
< prev
next >
Wrap
Text File
|
2000-08-23
|
2KB
|
64 lines
; Simple example of single data items per tag
INCDIR "include:"
XINCLUDE "scalos/preferences.bb2"
prefname$ = "Example" ; Name to refer to PrefsHandle with
; First of all we need to allocate a PrefsHandle by name
; (There is no specific type for a PrefsHandle, as long as it is a long or a pointer)
*prefhandle.l = AllocPrefsHandle_(&prefname$)
If *prefhandle
NPrint "PrefsHandle successfully allocated"
; We need an ID and Tag value to refer to a specific preference with
; so we create that here (or you could just use them in the library calls)
; Remember that the ID must be a long created from 4 ASCII characters
; and the Tag cannot be 0
ID.l = Cvl("MAIN")
Tag.l = 1
; The data we want to store in this preference item is defined now
prefdata$ = "This is some example preference data"
; Store the preference data in the prefs handle, under the ID and Tag
; The reason we pass a length of Len()+1 is so that the NULL terminator
; for the string will be stored as well
SetPreferences_ *prefhandle, ID, Tag, &prefdata$, Len(prefdata$)+1
; Use FindPreferences_ to check that the item has been stored
*prefstruct.PrefsStruct = FindPreferences_(*prefhandle, ID, Tag)
If *prefstruct
NPrint "Preference data found!"
NPrint "Size of string stored = ",Len(prefdata$)+1
NPrint "Size of pref data = ",*prefstruct\ps_Size
; And finally, just to show that the preference data was stored,
; we use GetPreferences_ to retrieve the data from memory
; Create some memory space to store the returned data
Dim temp.b(256)
datasize.l = GetPreferences_(*prefhandle, ID, Tag, &temp(0), 256)
NPrint "Bytes retrieved from pref data = ",datasize
If datasize > 0
NPrint "Contents of pref data:"
NPrint Peek$(&temp(0))
End If
Else
NPrint "Preference data was not stored!"
End If
; Finally we free the prefs handle
FreePrefsHandle_ *prefhandle
End If
NPrint "Press LMB+RMB to quit"
While Joyb(0)<>3
Delay_ 1
Wend
End