[Gambas-user] saving files

Benoit Minisini gambas at ...1...
Wed Dec 29 16:06:28 CET 2004


On Wednesday 29 December 2004 15:51, Jochen Georges wrote:
> On Wednesday 29 December 2004 11:09, Benoit Minisini wrote:
> > On Wednesday 29 December 2004 08:20, Jochen Georges wrote:
> > > Hello gambanauts,
> > >
> > > i would like to save an object of a selfdefined class into a file, just
> > > like
> > > http://www.binara.com/gambas-wiki/bin/view/Gambas/MiscFilesMydatatype
> > >
> > > But this does not work ??
> > > -----------------------------------------------------------------------
> > >- PUBLIC mc AS MyClass
> > >
> > > PUBLIC SUB _new()
> > >   mc = NEW MyClass
> > > END
> > >
> > > PUBLIC SUB Button1_Click()
> > >   myFile AS File
> > >   OPEN "/home/jochen/test.mcf" FOR CREATE AS myFile
> > >     'mc.WriteTo(myFile) 'unknown symbol 'WriteTo' in class 'MyClass'
> > >       'but it works in the wiki-example !?
> > >       'can't find information about WriteTo
> > >     'WRITE myFile,mc 'Type mismatch: wanted Integer Type, got MyClass
> > > instead WRITE #myFile,mc 'Type mismatch: wanted Standard Type, got
> > > MyClass instead CLOSE myFile
> > > END
> > > -----------------------------------------------------------------------
> > >- 'MyClass.class:
> > > wort AS String
> > > zahl AS Integer
> > >
> > > PUBLIC SUB _new()
> > >  wort = "Hallo"
> > >  zahl = 3
> > > END
> > > -----------------------------------------------------------------------
> > >-
> > >
> > > Thanks for any hint.
> > >
> > > Beste Gruesse
> > > Jochen
> >
> > Gambas object are not (yet) serializable. So, if you want to write them
> > into a file, you must do it yourself. For example, by implementing a
> > 'WriteTo' method in the class ?
>
> Hi Benoit,
>
> Why does it work in the wikiexample ??

The wiki is not the IDE :-) More seriously, the example is not complete: the 
method WriteTo() and ReadFrom() are missing.

> In the class CCar is no method WriteTo !!
>
> How does a method WriteTo look like?

Just take the File object as parameter, and use it to write the contents of 
your object.

You can write the data in ASCII with PRINT, or in binary with WRITE. It 
depends on what format you need.

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the User mailing list