//////////////////////////////////////////////////////////// {$ifndef ClassList} {$define ClassList} //interface //////////////////////////////////////////////////////////// TClassList = class(TObject) private protected FList: TListClone; FOwnsObjects: Boolean; function GetItem(Index: Integer): TClassListItem; function GetCount: Integer; public constructor Create; destructor Destroy; override; function Add(Item:TClassListItem): Integer; procedure Delete(Index: Integer); procedure Insert(Index: Integer; Item: TClassListItem); procedure Move(CurIndex, NewIndex: Integer); procedure Exchange(Index1, Index2: Integer); procedure Clear; function IndexOf(const Value: TClassListItem): Integer; property Items[Index:Integer]:TClassListItem read GetItem;default; property Count: Integer read GetCount; property OwnsObjects: Boolean read FOwnsObjects write FOwnsObjects default True; end; //////////////////////////////////////////////////////////// {$else} //implementation //////////////////////////////////////////////////////////// //------------------------------- { TClassList } //------------------------------- function TClassList.Add(Item:TClassListItem): Integer; begin result := FList.Add(Item); end; procedure TClassList.Clear; var i: Integer; begin if OwnsObjects then for i := 0 to FList.Count-1 do begin TClassListItem(FList.Items[i]).Free; end; FList.Clear; end; constructor TClassList.Create; begin FOwnsObjects := True; FList := TListClone.Create; end; procedure TClassList.Delete(Index: Integer); begin if OwnsObjects then TClassListItem(FList.Items[Index]).Free; FList.Delete(Index); end; destructor TClassList.Destroy; begin Self.Clear; FList.Free; inherited; end; procedure TClassList.Exchange(Index1, Index2: Integer); begin FList.Exchange(Index1, Index2); end; function TClassList.GetCount: Integer; begin result := FList.Count; end; function TClassList.GetItem(Index: Integer): TClassListItem; begin result := TClassListItem(FList[Index]); end; function TClassList.IndexOf(const Value: TClassListItem): Integer; begin Result := FList.IndexOf(Value); end; procedure TClassList.Insert(Index: Integer; Item: TClassListItem); begin FList.Insert(Index, Item); end; procedure TClassList.Move(CurIndex, NewIndex: Integer); begin FList.Move(CurIndex, NewIndex); end; //////////////////////////////////////////////////////////// {$endif} ////////////////////////////////////////////////////////////