How to implement TCollection.SaveToStream (Views: 27)
Problem/Question/Abstract: I need to implement a streaming capability for a TCollection class object. Is there anyone who knows how to do it? Answer: I do it via the following two utility procedures: procedure ReadCollection(s: TStream; c: TCollection); var Reader: TReader; begin Reader := TReader.Create(s, 1024); try Reader.ReadValue; {collection marker} Reader.ReadCollection(c); finally Reader.Free; end; end; procedure WriteCollection(s: TStream; c: TCollection); var Writer: TWriter; begin Writer := TWriter.Create(s, 1024); try Writer.WriteCollection(c); finally Writer.Free; end; end; Both procedures assume that the stream has been created and positioned correctly. |