Unit 'Objects' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#rtl]

TStringCollection.Compare

Compare two strings in the collection.

Declaration

Source position: objects.pp line 499

function TStringCollection.Compare(

  Key1: Pointer;

  Key2: Pointer

):Sw_Integer; virtual;

Description

TStringCollection overrides the Compare function so it compares the two keys as if they were pointers to strings. The compare is done case sensitive. It returns the following results:

-1
if the first string is alphabetically earlier than the second string.
0
if the two strings are equal.
1
if the first string is alphabetically later than the second string.

Errors

None.

See also

TSortedCollection.Compare

  

Compare two items in the collection.

Example

Program ex37;

{ Program to demonstrate the TStringCollection.Compare method }

Uses Objects;

Var C : PStringCollection;
    S : String;
    I : longint;

begin
  Randomize;
  C:=New(PStringCollection,Init(120,10));
  C^.Duplicates:=True; { Duplicates allowed }
  Writeln ('Inserting 100 records at random places.');
  or:=1 to 100 do
    begin
    Str(Random(100),S);
    S:='String with value '+S;
    C^.Insert(NewStr(S));
    end;
  or:=0 to 98 do
    With C^ do
    If Compare (At(i),At(I+1))=0 then
      Writeln ('Duplicate string found at position ',i);
  Dispose(C,Done);
end.

Documentation generated on: Dec 26 2024