ex34.pp 681 B

1234567891011121314151617181920212223242526272829303132333435
  1. Program ex34;
  2. { Program to demonstrate the TCollection.AtInsert 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. Randomize;
  13. C:=New(PCollection,Init(120,10));
  14. Writeln ('Inserting 100 records at random places.');
  15. For I:=1 to 100 do
  16. begin
  17. M:=New(PMyObject,Init);
  18. M^.SetField(I-1);
  19. If I=1 then
  20. C^.Insert(M)
  21. else
  22. With C^ do
  23. AtInsert(Random(Count),M);
  24. end;
  25. Writeln ('Values : ');
  26. C^.Foreach(@PrintField);
  27. Dispose(C,Done);
  28. end.