I trying to write a custom type to a file using RandomAccessFile.
My type is defined as:
Im saving the file using this code:
And reading it with:
When I debug the writing sub i can see stars=Bitmap and nebula=Bitmap in the Global variables panel. When I debug the reading sub I see stars=null and nebula=null and the code fails after the ReadObject line.
I dont understand what Im doing wrong... can you please help?
My type is defined as:
B4X:
Type opt (stars As Bitmap, nebula As Bitmap, magnitude As Int, star As Boolean, obj As String, fl As String, EPFl As String, epAFOV As String, notes As String)
Im saving the file using this code:
B4X:
option.stars=Stars.Bitmap
option.nebula=Nebula.Bitmap
option.obj=obj.Text
option.magnitude=magnitude.Value
option.star=star.Checked
option.fl=FL.Text
option.EPFl=EPFl.Text
option.epAFOV=epAFOV.Text
option.notes=Notes.text
raf.Initialize(Path, filename, False)
raf.WriteObject(option, True, raf.CurrentPosition)
raf.Close
And reading it with:
B4X:
Dim raf As RandomAccessFile
Dim s,n As Bitmap
Dim srect, nrect As Rect
raf.Initialize(File.DirRootExternal & "/Astropad", "drawing.dat", False)
option=raf.ReadObject(raf.CurrentPosition)
srect.Initialize(0,0,option.stars.Width,option.stars.height)
nrect.Initialize(0,0,option.nebula.Width,option.nebula.height)
Stars.DrawBitmap(s,srect,srect)
Nebula.DrawBitmap(n,nrect,nrect)
magnitude.Value=raf.ReadObject(raf.CurrentPosition)
star.checked=raf.ReadObject(raf.CurrentPosition)
obj.text=raf.ReadObject(raf.CurrentPosition)
FL.text=raf.ReadObject(raf.CurrentPosition)
EPFl.text=raf.ReadObject(raf.CurrentPosition)
epAFOV.text=raf.ReadObject(raf.CurrentPosition)
Notes.text=raf.ReadObject(raf.CurrentPosition)
When I debug the writing sub i can see stars=Bitmap and nebula=Bitmap in the Global variables panel. When I debug the reading sub I see stars=null and nebula=null and the code fails after the ReadObject line.
I dont understand what Im doing wrong... can you please help?