Как сохранять и загружать файлы с полу-определенными типами данных


Программа сохраняет двоичный файл в домашней директории.
mydatatype.png
car AS CCar
auto AS CCar
arCar AS Object[]

PUBLIC SUB _new()
myFile AS File
car = NEW CCar("ford", 150, 340.56)
auto = NEW CCar
arCar = NEW Object[]
arCar.Add(car)
arCar.Add(auto)
OPEN System.Home &/"test.jgf" FOR CREATE AS myFile
car.WriteTo(myFile)
'Gambas can not save this object as one thing to a file
'so the class CCar has to have a method which writes each variable
'on its own to the file
CLOSE myFile
END

PUBLIC SUB Button2_Click()
myFile AS File
IF Dialog.OpenFile() THEN RETURN
OPEN Dialog.Path FOR READ AS myFile
auto.ReadFrom(myFile)
CLOSE myFile

TextLabel1.Text = auto.getBrand() & "<br>" &
Str(auto.getPS_Power()) & "<br>" &
Str(auto.getKW_Power()) & "<br>" &
Str(auto.getPrice()) & "<br>"

END

См. исходник Ccar-Class здесь: OopCcar

-- JochenGeorges - 28 Dec 2004