### Save and Restore Types

To save and restore Types, an option is to use the jRandomAccessFile Library.
This library provides various methods, like write and read objects from a file.
The usage of objects offers a variety of possibilities to handle data storage in the example case.
Example
To write and read a list of type data from a file located in the appdir.
Define the globals Type, Items List and Items File
Type ItemData (Name As String, Phone As String, EMail As String)
Private glstItems As List
Private gstrItemsFile As String = "items.lst"
Create the list with some test data
glstItems.Initialize
For i = 0 To 4
Dim cdItem As ItemData
cdItem.Initialize
cdItem.Name = "Name " & i
cdItem.Phone = "Phone " & i
cdItem.EMail = "EMail " & i
glstItems.Add(cdItem)
Next
Save the list to the file located in the appdir
Dim raf As RandomAccessFile
Try
raf.Initialize(File.DirApp, gstrItemsFile, False)
raf.WriteObject(glstItems, True, 0)
raf.Close
Catch
Log(LastException.Message)
End Try
Read the list from the file located in the appdir
Dim raf As RandomAccessFile
Try
raf.Initialize(File.DirApp, gstrItemsFile, False)
glstItems = raf.ReadObject(0)
raf.Close
Catch
Log(LastException.Message)
End Try

Changed: 2018-06-07 09:26, Category: Type Definition, File: T6C274M2030.htm, ID: 2030