TSortedCollection object
Abstract sorted collection.
Declaration
TSortedCollection = class(TCollection)Inheritance
- TSortedCollection
- TCollection
- TPersistent
- 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
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
Init | Instantiates a new instance of a TSortedCollection. | |
Load | Instantiates a new instance of a TSortedCollection and loads it from stream. | |
KeyOf | Return the key of an item. | |
IndexOf | Return index of an item in the collection. | |
Compare | Compare two items in the collection. | |
Search | Search for item with given key. | |
Insert | Insert new item in collection. | |
Store | Write the collection to the stream. |
Fields
Duplicates | If 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.
