[Gambas-user] write a binary file

Benoît Minisini gambas at ...1...
Wed Feb 12 00:02:05 CET 2003


Le Mardi 11 Février 2003 21:04, Jochen Georges a écrit :
> hello gambasians,
>
> this is the next of my 1001 questions ;-)
>
> i have got an object of the selfdefined class CCar
> the name of the object is car
>
> i want to save car in a file, but i do not know how:
> i tried different things, but .....
>
> this way i got a type missmatch:
>
> PUBLIC SUB MenuSave_Click()
>   MyFile AS File
>   'OPEN "test.jgf" FOR WRITE DIRECT AS MyFile
>   OPEN "test.jgf" FOR CREATE DIRECT AS MyFile
>   WRITE #MyFile, car
>   CLOSE MyFile
> END
>
>
> thanks for any help.
>
> beste gruesse
> jochen
>
>

Alas, at the moment, objects do not know how to write themselves to a stream. 
A standard format should be created for that.

To solve your problem, create a public method in CCar to write each CCar field 
to the stream :

CCar.class:

PUBLIC SUB WriteTo(hFile AS File)

  WRITE #hFile, Field1
  WRITE #hFile, Field2
  ...
  WRITE #hFile, FieldN

END

But your request is not stupid :-) I add it to the gambas TODO file !

-- 
Benoît Minisini
mailto:gambas at ...1...






More information about the User mailing list