CBFalconer wrote:
Neil Santos wrote:
I've been using Pascal a while, but it was only recently that I decided to use Pascal for OO programming. Having only used records and typed files up to this point, I'm wondering how objects are saved to stream. ... snip ...
Section 6.7.5.2 of ISO10206 standard spells it all out.
Not really. ISO does not make any statements about the representation of data in the file. If defines any abstract idea of a file whose relation to a file on disk (if at all) is completely unspecified.
Even if assuming that a typed file will store the elements to equally sizes and structured chunks in the file (which is reasonable to assume, and given by GPC), the structure of a chunk is still unknown. In GPC (like probably most other compilers) it corresponds to the layout in memory which again is unspecified in general and can depend on options (alignment etc.).
Second, as "OO" implies, `object' here clearly has the OOP meaning. ISO Pascal doesn't deal with OOP at all.
To answer the original question, we have to know how you save objects. Typed files, untyped files and `BlockWrite', the Chief's FreeVision unit? I suppose the latter when you say "stream", and in this case, probably the Chief should answer.
Generally though, objects are stored mostly like records -- however with an additional field (VMT pointer). The FreeVision unit should take care of that field, I suppose. Objects inside an object (i.e., not a pointer, but a field that is an object) are like records within a record, but *both* with a VMT pointer. (I don't know if the FreeVision unit handles this case.)
Pointers (to objects and in general) are more tricky in files since they need to be encoded. (The memory location is meaningless when loading the file from another process.) I wrote some thoughts about this before (cf. "GPI files"). AFAIK, the FreeVision unit doesn't do anything about it.
The most useful answer, though, may be, the file format is undefined. You can expect to read it back with the program, compiled with the same compiler, as long as the relevant data structures are not changed, on the same platform, not much more. To create/read portable files, you'll have to use types with fixed size (attribute `Size' in GPC) and take care of endianness, or convert everything to/from a byte stream or similar yourself.
Frank