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

TSortedCollection

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

Abstract sorted collection.

Declaration

Source position: objects.pp line 440

type TSortedCollection = object(TCollection)

  Duplicates: Boolean;

  

If True duplicate strings are allowed in the collection.

  constructor Init();

  

Instantiates a new instance of a TSortedCollection

  constructor Load();

  

Instantiates a new instance of a TSortedCollection and loads it from stream.

  function KeyOf(); virtual;

  

Return the key of an item

  function IndexOf(); virtual;

  

Return index of an item in the collection.

  function Compare(); virtual;

  

Compare two items in the collection.

  function Search(); virtual;

  

Search for item with given key.

  procedure Insert(); virtual;

  

Insert new item in collection.

  procedure Store();

  

Write the collection to the stream.

end;

Inheritance

TSortedCollection

  

Abstract sorted collection.

TCollection

  

Manage a collection of pointers of objects

TObject

  

Basis of all objects

Description

TSortedCollection is an abstract class, implementing a sorted collection. You should never use an instance of TSortedCollection directly, instead you should declare a descendent type, and override the Compare method.

Because the collection is ordered, TSortedCollection overrides some TCollection methods, to provide faster routines for lookup.

The Compare method decides how elements in the collection should be ordered. Since TCollection has no way of knowing how to order pointers, you must override the compare method.

Additionally, TCollection provides a means to filter out duplicates. if you set Duplicates to False (the default) then duplicates will not be allowed.

The example below defines a descendent of TSortedCollection which is used in the examples.

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.

Documentation generated on: Jun 23 2021