ex38.pp 649 B

1234567891011121314151617181920212223242526272829
  1. Program ex38;
  2. { Program to demonstrate the TStrCollection.Compare method }
  3. Uses Objects,Strings;
  4. Var C : PStrCollection;
  5. S : String;
  6. I : longint;
  7. P : Pchar;
  8. begin
  9. Randomize;
  10. C:=New(PStrCollection,Init(120,10));
  11. C^.Duplicates:=True; { Duplicates allowed }
  12. Writeln ('Inserting 100 records at random places.');
  13. For I:=1 to 100 do
  14. begin
  15. Str(Random(100),S);
  16. S:='String with value '+S;
  17. P:=StrAlloc(Length(S)+1);
  18. C^.Insert(StrPCopy(P,S));
  19. end;
  20. For I:=0 to 98 do
  21. With C^ do
  22. If Compare (At(I),At(I+1))=0 then
  23. Writeln ('Duplicate string found at position ',I);
  24. Dispose(C,Done);
  25. end.