[fpc-pascal] Unit/library for writing data structures to files

David W Noon david.w.noon at ntlworld.com
Mon Aug 11 01:10:23 CEST 2008


On Sun, 2008-08-10 at 16:51 -0400, Francisco Reyes wrote:

> Michael Van Canneyt writes:
> 
> > You can also try the Classes unit if you use object oriented programming.
> > Each component can write itself to stream.
> 
> Played a little bit with the Classes unit.
> Don't really see any benefit over justin writing records directly.
> Am I missing something?
> 
> Also when reading back, on both cases(class or directly using records) it 
> seems I need to use fixed length records. At least based on the examples I 
> have seen so far. Is there a way to save variable length records and then 
> read them back?

Normally you write the length as a prefix before the record, typically
as some kind of integer type (e.g. LongWord or TsSize). When you read
the record later you read the length prefix first, then read the number
of bytes that the prefix specified. As a rough and ready example:

	in_file := FpOpen('input_data.dat', O_RdOnly);
	.
	{ Other stuff goes here. }
	.
	bytes_read := FpRead(in_file, record_len, sizeof(record_len));

	bytes_read := FpRead(in_file, buf_area, record_len);


Incidentally, from your first message in this thread, you said you were
writing an OLAP application. You might care to look at PostgreSQL as a
database manager. It does rather nice OLAP functionality, straight out
of the box -- and it's free.

Regards,
Dave [RLU#314465]
======================================================
david.w.noon at ntlworld.com (David W Noon)
======================================================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20080811/687acf1b/attachment.sig>


More information about the fpc-pascal mailing list