| Class TContainer (unit Containr) |
| Constructors |
constructor Load(S: TFilter);| Functions |
function Add(Item: Pointer): Integer;
procedure Assign(Container: TContainer);
procedure BeginUpdate;
procedure Clear;
procedure Delete(Index: Integer);
procedure DeleteItem(Item: Pointer);not sorted
destructor Destroy;
procedure EndUpdate;
procedure Exchange(Index1, Index2: Integer);
function Find(Item: Pointer; var Index: Integer): Boolean;
function FindKey(Key: Pointer; var Index: Integer): Boolean;
function First: Pointer;
function IndexOf(Item: Pointer): Integer;
function Insert(Index: Integer; Item: Pointer): Integer;
function Last: Pointer;
procedure Move(CurIndex, NewIndex: Integer);
procedure Remove(Index: Integer);
procedure RemoveAll;
procedure RemoveItem(Item: Pointer);
procedure Sort;
procedure Store(S: TFilter);
function ValidIndex(Index: Integer): Boolean;
procedure Changed;
function CheckNewKey(CurKey, NewKey: Pointer): Boolean;
function Compare(Key1, Key2: Pointer): Integer;
procedure FreeDataStructure;
procedure FreeDuplicate(Item: Pointer);
procedure FreeItem(Item: Pointer);
function Get(Index: Integer): Pointer;
function GetCount: Integer;
function GetItem(S: TFilter): Pointer;
function GetString(Index: Integer): String;
function KeyOf(Item: Pointer): Pointer;
procedure ListInsert(Index: Integer; Item: Pointer);
procedure ListPut(Index: Integer; Item: Pointer);
procedure ListRemove(Index: Integer);
procedure Put(Index: Integer; Item: Pointer);
procedure PutItem(Item: Pointer; S: TFilter);
procedure SetOwnesItems(Value: Boolean);
procedure SetUpdateState(Updating: Boolean);
procedure StyleChanged;
function CheckDuplicates(Item: Pointer): Pointer;
procedure DeleteDuplicates;
procedure QuickSort(L, R: Integer);
procedure SetCanSort(Value: Boolean);
procedure SetDuplicates(Value: TContainerDuplicates);
procedure SetSorted(Value: Boolean);| Properties |
property Count : Integer
property Duplicates : TContainerDuplicates
property Items : Pointer
property OwnesItems : Boolean
property Sorted : Boolean
property Strings : String
property CanSort : Boolean| Events |
event OnChange : TNotifyEvent
event OnStyleChange : TNotifyEvent| Variables |
FCanSort : Boolean;
FDuplicates : TContainerDuplicates;
FOnChange : TNotifyEvent;
FOnStyleChange : TNotifyEvent;
FOwnesItems : Boolean;
FSorted : Boolean;
FUpdateCount : Integer;| Constructors |
constructor Load(S: TFilter);Stores wheter container is able to sort or not. To be set by Create
| Functions |
function Add(Item: Pointer): Integer;Sets FOnChange to nil, preventing change message's to be send during destruction, then calls FreeDataStructire and inherited Destroy
procedure Assign(Container: TContainer);Checkes for duplicates and sorting order, then calls ListInsert to insert item at correct position. Add returns the position at which the item was added or -1 if it was not added at all
procedure BeginUpdate;List is cleared. Adds all items in Container by repeatedly calling Add. If Container = nil, list is cleared anyway
procedure Clear;Increments UpdateCount and calls SetupdateState(True). Locking mechanism. Always lock and unlock updates with pairs of BeginUpdate and EndUpdate method calls
procedure Delete(Index: Integer);Clears all items in container. Disposes of items if OwnedItems is True. Clear is identical to 'DeleteAll'
procedure DeleteItem(Item: Pointer);Deletes item at Index from container, calls FreeItem if OwnesItem is True
not sorted
destructor Destroy;Loads properties from S and then reads items calling GetItem. Add is used to add items to container. Note: Descendants should therefore make sure that the data structure in which items are stored is initialised before inherited load is called, See TCollection.Load. Inherited Load should ALWAYS be called before any loading from s is done however.
procedure EndUpdate;Exchages items at Index1 and Index2. Safe when container is Sorted.
procedure Exchange(Index1, Index2: Integer);Deletes item from container, uses Find to locate it, then calls Delete
function Find(Item: Pointer; var Index: Integer): Boolean;returns pointer to first item or nil if no such item exists
function FindKey(Key: Pointer; var Index: Integer): Boolean;Returns FindKey(KeyOf(Item)
function First: Pointer;Decrements the UpdateCounter. Update locking mechanism. If EndUpdate hits UpdateCount = 0, SetUpdateState(False) is called
function IndexOf(Item: Pointer): Integer;Returns True if Item is found. Index then contains the index at which Key was found. If False is returned Index containes the value at which Key would be inserted
function Insert(Index: Integer; Item: Pointer): Integer;Calls Find and returns index of Item, or -1 if it was not found
function Last: Pointer;Checkes for sorting order and duplicates, then inserts item calling ListInsert. Note: if Sorted is True, calling Insert has the same result as calling Add. Insert always returns the position at which the item was inserted or -1 if it was not inserted at all
procedure Move(CurIndex, NewIndex: Integer);returns pointer to last item or nil if no such item exists
procedure Remove(Index: Integer);Moves the item at CurIndex to NewIndex. Implemented with Remove and Insert methods. Also safe for sorted containers in which case nothing will happen (except when duplicates are accepted in which case the order of the duplicate items might be changed
procedure RemoveAll;Removes the item from the container without destroying it even if OwnesItems is true. Implemented as calling ListRemove.
procedure RemoveItem(Item: Pointer);Removes all items by iterating over container and calling Remove
procedure Sort;Stores properties to S. Then stores each item to S calling PutItem
procedure Store(S: TFilter);Removes Item by calling Find and Remove, does not destroy the item
function ValidIndex(Index: Integer): Boolean;Calls quicksort if nessecary
procedure Changed;
function CheckNewKey(CurKey, NewKey: Pointer): Boolean;Called whenever the list is changed. Calls FOnChanged if it is assigned Change mechanism is locked when FUpdateCount > 0. Note: Changed does NOT check for changes in the contents of the list. Changes in items should be reflected by replacing them in the Container using the Put method. This will also take care of correct sorting if a key field was changed
function Compare(Key1, Key2: Pointer): Integer;Could be called by items in a duplicate restricted list in order to validate a change of their key.
procedure FreeDataStructure;Called whenever an owned item has to be disposed of. Assumes Item to be a TObject descendnat and calls it's Free method
procedure FreeDuplicate(Item: Pointer);Called form Destroy ONLY. Calls Clear if FOwnesItems is True else RemoveAll. Descendants should free their data structure and also free their items if FOwnesItems = True
procedure FreeItem(Item: Pointer);Returns 0 if Key1 = Key2. Descendants should override this method in order to create some sorting order if required
function Get(Index: Integer): Pointer;Called if an attempt was made to insert a duplicate item, in dupDestroy mode. Implemented as calling FreeItem. Descendants could generate an appropriate error / warning
function GetCount: Integer;Should give acces to indexed property Items
function GetItem(S: TFilter): Pointer;Should returns number of items in container
function GetString(Index: Integer): String;Used to retrieve stored items from S. Assumes TStreamable descendants to be stored on S and calls S.Get to retrive it
function KeyOf(Item: Pointer): Pointer;Should give acces to string representation of Items[Index], this could e.g. be used in displaying the container in a TListBox object
procedure ListInsert(Index: Integer; Item: Pointer);Returns Key for Comparison. Duplicate handling and sorting is based on the KeyOf / Compare methods. Implemented as returning Item
procedure ListPut(Index: Integer; Item: Pointer);Performs actual insertion in container called by Add and Insert after duplicates and sorting order have been checked
procedure ListRemove(Index: Integer);Should put Item at Index. All checking has been done
procedure Put(Index: Integer; Item: Pointer);Should remove item from container without destroying it. Called by Delete and Remove methods
procedure PutItem(Item: Pointer; S: TFilter);Gives acces to indexed property Items. Calls Remove and Insert to implement behaviour. Also safe for sorted containers
procedure SetOwnesItems(Value: Boolean);Used to store items to stream. assumes Item to be a TStreamable descendant and Put's it on S. Descendants could override this method in order to store items different, e.g. when items are strings
procedure SetUpdateState(Updating: Boolean);Simply sets FOwnesItems to Value
procedure StyleChanged;Calls Changed if Updating is False
function CheckDuplicates(Item: Pointer): Pointer;
procedure DeleteDuplicates;This items being removed might have caused related items to be removed. Therefore do not count on Index here anymore, but instead refer to item
procedure QuickSort(L, R: Integer);
procedure SetCanSort(Value: Boolean);
procedure SetDuplicates(Value: TContainerDuplicates);
procedure SetSorted(Value: Boolean);| Properties |
property Count : IntegerReturns True if Index in range of [0.. Count>
property Duplicates : TContainerDuplicatesreturns number of items
property Items : PointerControls duplicates behavior
property OwnesItems : BooleanDispatched each time the list style (sorted etc) changes
property Sorted : BooleanControls ownership of items in list. If set True FreeItem is called whenever an item is Deleted from the list
property Strings : StringControls the sorting behavior. If Sorted is set from False to True the container will (re-) sort it's contents
property CanSort : BooleanCalls FOnStyleChanged if it is assigned
| Events |
event OnChange : TNotifyEventItems in containr , default property
event OnStyleChange : TNotifyEventDispatched each time the list container changes
| Variables |
FCanSort : Boolean;
FDuplicates : TContainerDuplicates;
FOnChange : TNotifyEvent;
FOnStyleChange : TNotifyEvent;
FOwnesItems : Boolean;
FSorted : Boolean;
FUpdateCount : Integer;