ex21.pp 569 B

1234567891011121314151617181920212223242526272829
  1. Program ex21;
  2. { Program to demonstrate the TCollection.Foreach method }
  3. Uses Objects,MyObject; { For TMyObject definition and registration }
  4. Var C : PCollection;
  5. M : PMyObject;
  6. I : Longint;
  7. Procedure PrintField (Dummy: Pointer;P : PMyObject);
  8. begin
  9. Writeln ('Field : ',P^.GetField);
  10. end;
  11. begin
  12. C:=New(PCollection,Init(100,10));
  13. For I:=1 to 100 do
  14. begin
  15. M:=New(PMyObject,Init);
  16. M^.SetField(100-I);
  17. C^.Insert(M);
  18. end;
  19. Writeln ('Inserted ',C^.Count,' objects');
  20. C^.ForEach(@PrintField);
  21. C^.FreeAll;
  22. Dispose(C,Done);
  23. end.