ex25.pp 702 B

123456789101112131415161718192021222324252627282930313233
  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. Function CheckField (Dummy: Pointer;P : PMyObject) : Longint;
  8. begin
  9. If P^.GetField<56 then
  10. Checkfield:=1
  11. else
  12. CheckField:=0;
  13. end;
  14. begin
  15. C:=New(PCollection,Init(100,10));
  16. For I:=1 to 100 do
  17. begin
  18. M:=New(PMyObject,Init);
  19. M^.SetField(I);
  20. C^.Insert(M);
  21. end;
  22. Writeln ('Inserted ',C^.Count,' objects');
  23. Writeln ('Last one for which Field<56 has index (should be 54) : ',
  24. C^.IndexOf(C^.LastThat(@CheckField)));
  25. C^.FreeAll;
  26. Dispose(C,Done);
  27. end.