ex35.pp 657 B

1234567891011121314151617181920212223242526272829303132
  1. Program ex35;
  2. { Program to demonstrate the TSortedCollection.Insert method }
  3. Uses Objects,MyObject,MySortC;
  4. { For TMyObject,TMySortedCollection definition and registration }
  5. Var C : PSortedCollection;
  6. M : PMyObject;
  7. I : Longint;
  8. Procedure PrintField (Dummy: Pointer;P : PMyObject);
  9. begin
  10. Writeln ('Field : ',P^.GetField);
  11. end;
  12. begin
  13. Randomize;
  14. C:=New(PMySortedCollection,Init(120,10));
  15. Writeln ('Inserting 100 records at random places.');
  16. For I:=1 to 100 do
  17. begin
  18. M:=New(PMyObject,Init);
  19. M^.SetField(Random(100));
  20. C^.Insert(M)
  21. end;
  22. Writeln ('Values : ');
  23. C^.Foreach(@PrintField);
  24. Dispose(C,Done);
  25. end.