Platforms to show: All Mac Windows Linux Cross-Platform
/Main/Save State with Preferences File
Required plugins for this example:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Main/Save State with Preferences File
This example is the version from Sun, 17th Mar 2012.
Project "Save State with Preferences File.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Close()
pref.save
End EventHandler
EventHandler Sub Open()
pref.load
End EventHandler
End Class
Class Window1 Inherits Window
Control HTMLViewer1 Inherits HTMLViewer
ControlInstance HTMLViewer1 Inherits HTMLViewer
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
pref.CurrentURL = EditField1.text
pref.save
HTMLViewer1.LoadURL EditField1.text
End EventHandler
End Control
Control EditField1 Inherits TextField
ControlInstance EditField1 Inherits TextField
End Control
EventHandler Sub Open()
if pref.CurrentURL<>"" then
EditField1.text = pref.CurrentURL
HTMLViewer1.LoadURL pref.CurrentURL
end if
End EventHandler
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Module Pref
Const Preffilename = "Save State with Preferences File.pref"
Sub load()
dim file as FolderItem = SpecialFolder.Preferences.Child(Preffilename)
if file = nil then Return
dim t as TextInputStream = file.OpenAsTextFile
if t = nil then Return
t.Encoding = encodings.UTF8
while not t.EOF
dim line as string = t.ReadLine
dim p as integer = instr(line, "=")
if p>0 then
dim le as string = left(line,p-1)
dim ri as string = mid(line, p+1)
select case le
case "CurrentURL"
CurrentURL = ri
end select
end if
wend
End Sub
Sub save()
dim file as FolderItem = SpecialFolder.Preferences.Child(Preffilename)
if file = nil then Return
dim t as TextOutputStream = file.CreateTextFile
if t = nil then Return
t.WriteLine ConvertEncoding("CurrentURL="+CurrentURL, encodings.UTF8)
End Sub
Property CurrentURL As string
End Module
End Project
The items on this page are in the following plugins: MBS Main Plugin.