This is what I do to write a pref file

App.Preferences is a property of type Dictionary

This is the CreatePrefFile method

  Dim xml As XmlDocument
  Dim creator As XmlNode
  Dim output As TextOutputStream
  Dim OK As Boolean

  xml = new XmlDocument

  creator =xml.AppendChild(xml.CreateElement("creator"))


  output = f.CreateTextFile()
  output.Write(xml.toString)

  output.Close()
  if f = nil then
MsgBox "Kon Pref file niet creƫren."+ Chr(10) +"De toepassing zal worden afgesloten."
    OK = False
    Return OK
  else
    OK = True
    return OK
  end if


This is the ReadPrefFile method called on open loginwindow

  Dim xDoc As XmlDocument
  Dim Creator As XmlNode
  Dim output As TextOutputStream
  Dim f As FolderItem
  Dim Count, i As Integer
  Dim myKeys() As Variant
  Dim s,v As String

  f = PreferencesFolder.Child("eTutorPrefs.xml")
  if f.Exists then
    xdoc = New XmlDocument
    xdoc.PreserveWhitespace = True

    xdoc.LoadXml f
    Creator = xdoc.DocumentElement
    myKeys = Preferences.Keys
    Count = Preferences.Count-1
    for i = 0 to Count
      s =str(myKeys(i))
      v = Preferences.Value(myKeys(i))
      Creator.SetAttribute(s,v)
    next

    output = f.CreateTextFile
    output.Write(xdoc.toString)
    output.Close()
  end if

This is the WritePrefFile method called on close window

  Dim xDoc As XmlDocument
  Dim Creator As XmlNode
  Dim output As TextOutputStream
  Dim f As FolderItem
  Dim Count, i As Integer
  Dim myKeys() As Variant
  Dim s,v As String

  f = PreferencesFolder.Child("eTutorPrefs.xml")
  if f.Exists then
    xdoc = New XmlDocument
    xdoc.PreserveWhitespace = True

    xdoc.LoadXml f
    Creator = xdoc.DocumentElement
    myKeys = Preferences.Keys
    Count = Preferences.Count-1
    for i = 0 to Count
      s =str(myKeys(i))
      v = Preferences.Value(myKeys(i))
      Creator.SetAttribute(s,v)
    next

    output = f.CreateTextFile
    output.Write(xdoc.toString)
    output.Close()
  end if


As you can see there is no naming variables in the code. So if I need an extra pref it's added by calling

App.Preferences.Value("newKey") = newValue


hth

Bart Pietercil

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to