OpenPreferences()

Syntax

Result = OpenPreferences(Filename$ [, Flags])
Description
Opens a previously existing preference file.

Parameters

Filename$ The filename of the preference file.
Flags (optional) It can be a combination of the following values:
  #PB_Preference_NoSpace: no spaces will be put around the equal sign joining key and values.
                          It can be useful when dealing with external preferences files which doesn't
                          accept spaces around equal sign.
  #PB_Preference_GroupSeparator: add an empty line between the groups to ease readability of the file.

Return value

Nonzero if the file has been successfully opened, zero otherwise.

Remarks

If the file wasn't found or can't be opened, it is still possible to use the read functions and it will return the specified default value. It is very useful to initialize in one step the program variables. The functions like ReadPreferenceString() can be used to read the preference values stored in the file.

To remove a key or a group, use RemovePreferenceKey() and RemovePreferenceGroup(). To create or change the current group, use PreferenceGroup().

It is possible to change existing values with WritePreferenceString() and similar functions.

Once all write operations are done, ClosePreferences() needs to be called to really write the preferences back to disk (if it has been modified inbetween).

Example

  ; Open a preference file
  OpenPreferences(#PB_Compiler_Home +"examples/sources/Data/test.pref")
  
  ; Examine Groups
  ExaminePreferenceGroups()
  ; For each group
  While NextPreferenceGroup()
    text$ = text$ + PreferenceGroupName() + #LF$ ; its name
    ; Examine keys for the current group  
    ExaminePreferenceKeys()
    ; For each key  
    While  NextPreferenceKey()                      
      text$ = text$ + PreferenceKeyName() + " = " + PreferenceKeyValue() + #LF$ ; its name and its data
    Wend
    text$ = text$ + #LF$
  Wend

  ; Display all groups and all keys with datas
  MessageRequester("test.pref", text$)

  ; Close the preference file
  ClosePreferences()    

See Also

ClosePreferences()

Supported OS

All

<- NextPreferenceKey() - Preference Index - PreferenceComment() ->