ex36.pp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. Program ex36;
  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. C^.Duplicates:=True;
  16. Writeln ('Inserting 100 records at random places.');
  17. For I:=1 to 100 do
  18. begin
  19. M:=New(PMyObject,Init);
  20. M^.SetField(Random(100));
  21. C^.Insert(M)
  22. end;
  23. M:=New(PMyObject,Init);
  24. Repeat;
  25. Write ('Value to search for (-1 stops) :');
  26. read (I);
  27. If I<>-1 then
  28. begin
  29. M^.SetField(i);
  30. If Not C^.Search (M,I) then
  31. Writeln ('No such value found')
  32. else
  33. begin
  34. Write ('Value ',PMyObject(C^.At(I))^.GetField);
  35. Writeln (' present at position ',I);
  36. end;
  37. end;
  38. Until I=-1;
  39. Dispose(M,Done);
  40. Dispose(C,Done);
  41. end.