ex24.pp 723 B

123456789101112131415161718192021222324252627282930313233
  1. Program ex24;
  2. { Program to demonstrate the TCollection.IndexOf method }
  3. Uses Objects,MyObject; { For TMyObject definition and registration }
  4. Var C : PCollection;
  5. M,Keep : PMyObject;
  6. I : Longint;
  7. begin
  8. Randomize;
  9. C:=New(PCollection,Init(100,10));
  10. Keep:=Nil;
  11. For I:=1 to 100 do
  12. begin
  13. M:=New(PMyObject,Init);
  14. M^.SetField(I-1);
  15. If Random<0.1 then
  16. Keep:=M;
  17. C^.Insert(M);
  18. end;
  19. If Keep=Nil then
  20. begin
  21. Writeln ('Please run again. No object selected');
  22. Halt(1);
  23. end;
  24. Writeln ('Selected object has field : ',Keep^.GetField);
  25. Write ('Selected object has index : ',C^.IndexOf(Keep));
  26. Writeln (' should match it''s field.');
  27. C^.FreeAll;
  28. Dispose(C,Done);
  29. end.