home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 13
/
AACD13.ISO
/
AACD
/
System
/
ScalosPrefs
/
examples
/
Blitz
/
multiple.bb2
< prev
next >
Wrap
Text File
|
2000-08-23
|
3KB
|
74 lines
; Simple example of multiple data items within one tag
; You should have a look at the "single.bb2" example first
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 = 2
; We keep track of the current entry number so that we can keep on adding
; at the end of the list of data items. You can of course, pass any entry
; number and it will be inserted in the correct place in the list, unless
; the data item already exists and the size is the same then it will be overwritten
en.l = 0
; Enter a loop which allows the user to enter some data to be stored in the
; list.
Repeat
; Prompt user and get a string from them
Print "Enter a name or leave blank to quit and press return: "
prefdata$ = Edit$(256)
; If the string is empty, we do not do anything with it, as that
; is the condition for quitting the loop
If prefdata$<>""
; Store string as a preference
SetEntry_ *prefhandle, ID, Tag, &prefdata$, Len(prefdata$)+1, en
; increase entry number to store data at
en+1
End If
Until prefdata$=""
; Now we will show each data item in turn, as well as removing it,
; this means we do not need to play around with entry numbers here
; Create some memory for storing the retrieved data
Dim temp.b(256)
; While the amount of retrieved bytes is > 0 (this means that it was able
; to retrieve some data, and thus the list is not empty)
While(GetEntry_(*prefhandle, ID, Tag, &temp(0), 256, 0))
; Print the data retrieved and then remove that entry
NPrint "Retrieved: ",Peek$(&temp(0))
If RemEntry_(*prefhandle, ID, Tag, 0) Then NPrint "Entry removed" Else NPrint "Entry not removed"
Wend
; Finally we free the prefs handle
FreePrefsHandle_ *prefhandle
End If
NPrint "Press LMB+RMB to quit"
While Joyb(0)<>3
Delay_ 1
Wend
End