Browse Source

* Added sort method to TCollection

git-svn-id: trunk@12901 -
michael 16 years ago
parent
commit
a43bda5052
2 changed files with 13 additions and 0 deletions
  1. 2 0
      rtl/objpas/classes/classesh.inc
  2. 11 0
      rtl/objpas/classes/collect.inc

+ 2 - 0
rtl/objpas/classes/classesh.inc

@@ -428,6 +428,7 @@ type
 
 
   TCollectionItemClass = class of TCollectionItem;
   TCollectionItemClass = class of TCollectionItem;
   TCollectionNotification = (cnAdded, cnExtracting, cnDeleting);
   TCollectionNotification = (cnAdded, cnExtracting, cnDeleting);
+  TCollectionSortCompare = function (Item1, Item2: TCollectionItem): Integer;
 
 
   TCollection = class(TPersistent)
   TCollection = class(TPersistent)
   private
   private
@@ -467,6 +468,7 @@ type
     function GetNamePath: string; override;
     function GetNamePath: string; override;
     function Insert(Index: Integer): TCollectionItem;
     function Insert(Index: Integer): TCollectionItem;
     function FindItemID(ID: Integer): TCollectionItem;
     function FindItemID(ID: Integer): TCollectionItem;
+    procedure Sort(Const Compare : TCollectionSortCompare);
     property Count: Integer read GetCount;
     property Count: Integer read GetCount;
     property ItemClass: TCollectionItemClass read FItemClass;
     property ItemClass: TCollectionItemClass read FItemClass;
     property Items[Index: Integer]: TCollectionItem read GetItem write SetItem;
     property Items[Index: Integer]: TCollectionItem read GetItem write SetItem;

+ 11 - 0
rtl/objpas/classes/collect.inc

@@ -329,6 +329,17 @@ procedure TCollection.Notify(Item: TCollectionItem;Action: TCollectionNotificati
 begin
 begin
 end;
 end;
 
 
+procedure TCollection.Sort(Const Compare : TCollectionSortCompare);
+
+begin
+  BeginUpdate;
+  try
+    FItems.Sort(TListSortCompare(Compare));
+  Finally
+    EndUpdate;
+  end;
+end;
+
 
 
 {****************************************************************************}
 {****************************************************************************}
 {*                             TOwnedCollection                             *}
 {*                             TOwnedCollection                             *}