Streaming multiple TObjects to a TMemoryStream

Posted by Altar on Stack Overflow See other posts from Stack Overflow or by Altar
Published on 2010-05-25T11:54:26Z Indexed on 2010/05/25 12:51 UTC
Read the original article Hit count: 208

Filed under:

I need to store multiple objects (most of them are TObject/non persistent) to a TMemoryStream, save the stream to disk and load it back. The objects need to be streamed one after each other. Some kind of universal container.

I started to make several functions that store stuff to stream - for example function

StreamReadString(CONST MemStream: TMemoryStream): string; 
StreamWriteString(CONST MemStream: TMemoryStream; s: string);

However, it seems that I need to rewrite a lot of code. One of the many examples is TStringList.LoadFromStream that will not work so it needs to be rewritten. This is because TStringList needs to be the last object in the stream (it reads from current position to the end of the stream).

Anybody knows a library that provide basic functionality like this?


I am using Delphi 7 so RTTI won't help too much.

© Stack Overflow or respective owner

Related posts about delphi-7