Author: Tomas Rutkauskas
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:
1 procedure ReadCollection(s: TStream; c: TCollection);
2 var3 Reader: TReader;
4 begin5 Reader := TReader.Create(s, 1024);
6 try7 Reader.ReadValue; {collection marker}8 Reader.ReadCollection(c);
9 finally10 Reader.Free;
11 end;
12 end;
13 14 procedure WriteCollection(s: TStream; c: TCollection);
15 var16 Writer: TWriter;
17 begin18 Writer := TWriter.Create(s, 1024);
19 try20 Writer.WriteCollection(c);
21 finally22 Writer.Free;
23 end;
24 end;
Both procedures assume that the stream has been created and positioned correctly.