[Overview][Constants][Types][Classes][Procedures and functions][Variables] Reference for unit 'Objects' (#rtl)

TSortedCollection.Compare

Compare two items in the collection.

Declaration

Source position: objects.pp line 438

function TSortedCollection.Compare(

  Key1: Pointer;

  Key2: Pointer

):Sw_Integer; virtual;

Description

Compareis an abstract method that should be overridden by descendent objects in order to compare two items in the collection. This method is used in the Searchmethod and in the Insertmethod to determine the ordering of the objects.

The function should compare the two keys of items and return the following function results:

Result <0
If Key1is logically before Key2(Key1<Key2)
Result = 0
If Key1and Key2are equal. (Key1=Key2)
Result >0
If Key1is logically after Key2(Key1>Key2)

Errors

An 'abstract run-time error' will be generated if you call TSortedCollection.Comparedirectly.

See also

TSortedCollection.IndexOf

  

Return index of an item in the collection.

TSortedCollection.Search

  

Search for item with given key.

Example

Unit MySortC;

Interface

Uses Objects;

Type
  PMySortedCollection = ^TMySortedCollection;
  TMySortedCollection = Object(TSortedCollection)
       Function Compare (Key1,Key2 : Pointer): Sw_integer; virtual;
       end;

Implementation

Uses MyObject;

Function TMySortedCollection.Compare (Key1,Key2 : Pointer) :sw_integer;

begin
  Compare:=PMyobject(Key1)^.GetField - PMyObject(Key2)^.GetField;
end;

end.