Sign in Join
FPDoc Onlineexperiment

TSortedCollection object

In unit Objects

Abstract sorted collection.

Declaration

pascal
TSortedCollection = class(TCollection)

Inheritance

  1. TSortedCollection
  2. TCollection
  3. TPersistent
  4. TObject

Descends from it: TStrCollection TStringCollection

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: mysortc

pascal
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.

Methods

InitInstantiates a new instance of a TSortedCollection.
LoadInstantiates a new instance of a TSortedCollection and loads it from stream.
KeyOfReturn the key of an item.
IndexOfReturn index of an item in the collection.
CompareCompare two items in the collection.
SearchSearch for item with given key.
InsertInsert new item in collection.
StoreWrite the collection to the stream.

Fields

DuplicatesIf True duplicate strings are allowed in the collection.

Inherited

From TCollection (30)

Add Assign BeginUpdate Changed Clear Count Create Delete Destroy EndUpdate Exchange FindItemID GetAttr GetAttrCount GetEnumerator GetItem GetItemAttr GetNamePath ItemClass Items Move Notify Owner PropName SetItem SetItemName SetPropName Sort Update UpdateCount

From TPersistent (6)

AssignTo DefineProperties FPOAttachObserver FPODetachObserver FPONotifyObservers GetOwner

From TObject (40)

AfterConstruction BeforeDestruction CheckDisposed ClassInfo ClassName ClassNameIs ClassParent ClassType CleanupInstance DefaultHandler DefaultHandlerStr Dispatch DispatchStr Disposed DisposeOf Equals FieldAddress Free FreeInstance GetDisposed GetHashCode GetInterface GetInterfaceByStr GetInterfaceEntry GetInterfaceEntryByStr GetInterfaceTable GetInterfaceWeak GetLastCastErrorInfo InheritsFrom InitInstance InstanceSize MethodAddress MethodName newinstance QualifiedClassName SafeCallException StringMessageTable SystemHasExtendedRTTI ToString UnitName

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.