ex22.pp 632 B

123456789101112131415161718192021222324252627282930
  1. Program ex22;
  2. { Program to demonstrate the TCollection.Load method }
  3. Uses Objects,MyObject; { For TMyObject definition and registration }
  4. Var C : PCollection;
  5. M : PMyObject;
  6. I : Longint;
  7. S : PMemoryStream;
  8. begin
  9. C:=New(PCollection,Init(100,10));
  10. For I:=1 to 100 do
  11. begin
  12. M:=New(PMyObject,Init);
  13. M^.SetField(100-I);
  14. C^.Insert(M);
  15. end;
  16. Writeln ('Inserted ',C^.Count,' objects');
  17. S:=New(PMemorySTream,Init(1000,10));
  18. C^.Store(S^);
  19. C^.FreeAll;
  20. Dispose(C,Done);
  21. S^.Seek(0);
  22. C^.Load(S^);
  23. Writeln ('Read ',C^.Count,' objects from stream.');
  24. Dispose(S,Done);
  25. Dispose(C,Done);
  26. end.