{*------------------------------------------------------------------------------
  Some TCollection unit.

  @Author Unknown author
  @Version 0.1
  @Todo Make sure GetDisplayName has a proper return value
  @Todo Make sure all INI file fields are written using proper methods
  @Todo Make sure all sorting functions do proper comparisons
-------------------------------------------------------------------------------}
// *****************************************************************************
// Copyright: 2007 Unknown company/author. All rights reserved.
// Project:   [Name]
// File:      UnitCollectionTest.pas
// Compiler:  Delphi, FreePascal
// Purpose:   Some TCollection unit.
// Authors:   Unknown author
// *****************************************************************************
// Dependencies:
// <name of module>
// <name of further module>
// *****************************************************************************
// Used by:
// <name of project that uses this script>
// <name of further project that uses this script>
// *****************************************************************************
// Changelog (new entries first):
// ---------------------------------------
// 2007-04-25  --  ---  Unit created by CollectionCodeMaker
// *****************************************************************************

unit UnitCollectionTest;

// You may make your choices here:

{$DEFINE GUICollection}       // if you want to support TListView
{$DEFINE CollectionFiltering} // filtered views of the list
{$DEFINE CollectionSorting}   // sorting of the list
{$DEFINE CollectionIniOps}    // loading and saving to a INI file

// Please leave the following untouched:

{$IFNDEF FPC}
  {$DEFINE GUIAvail}
{$ELSE FPC}
  {$IFDEF LCL}
    // GUI functions only with proper LCL initialization:
    {$DEFINE GUIAvail}
  {$ENDIF LCL}
{$ENDIF FPC}

{$IFNDEF GUIAvail}
  {$UNDEF GUICollection}
{$ENDIF GUIAvail}

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF FPC}

interface

uses SysUtils,
     {$IFDEF GUICollection} ComCtrls, {$ENDIF GUICollection}
     Classes;

type
   TMyCollectionList = class;

   { TMyCollectionItem }

   TMyCollectionItem = class(TCollectionItem)
   private
      FOwner: TMyCollectionList;
      FTestString: string;
      FBlubbels: integer;
      FAbcdefg: string;
   protected
      function GetDisplayName: string; override;
   public
      constructor Create(ACollection: TCollection); override;
      destructor Destroy; override;
      procedure Assign(Source: TPersistent); override;
      {$IFDEF GUICollection}
      procedure ToListItem(const Item: TListItem);
      {$ENDIF GUICollection}
   published
      property TestString: string read FTestString write FTestString;
      property Blubbels: integer read FBlubbels write FBlubbels;
      property Abcdefg: string read FAbcdefg write FAbcdefg;
   end;

   { TMyCollectionList } 

   TMyCollectionList = class(TCollection)
   private
      {$IFDEF CollectionFiltering}
      FFilteredItems: array of TMyCollectionItem;
      function GetFilteredItem(Index: Integer): TMyCollectionItem;
      function GetFilteredCount: integer;
      procedure AddFilteredItem(Value: TMyCollectionItem);
      {$ENDIF CollectionFiltering}
      function GetItem(Index: Integer): TMyCollectionItem;
      procedure SetItem(Index: Integer; Value: TMyCollectionItem);
   public
      constructor Create;
      destructor Destroy; override;
      function Add: TMyCollectionItem;
      function CountTestString(const ATestString: string): integer;
      function CountBlubbels(const ABlubbels: integer): integer;
      function CountAbcdefg(const AAbcdefg: string): integer;
      function FindTestString(const ATestString: string): TMyCollectionItem;
      function FindBlubbels(const ABlubbels: integer): TMyCollectionItem;
      function FindAbcdefg(const AAbcdefg: string): TMyCollectionItem;
      {$IFDEF CollectionIniOps}
      procedure LoadFromINIFile(const AFilename: string);
      procedure SaveToINIFile(const AFilename: string);
      {$ENDIF CollectionIniOps}
      {$IFDEF CollectionFiltering}
      procedure ClearFilterList;
      function FilterTestString(const ATestString: string): integer;
      function FilterBlubbels(const ABlubbels: integer): integer;
      function FilterAbcdefg(const AAbcdefg: string): integer;
      function FilterBlubbelsMin(const ABlubbels: integer): integer;
      function FilterBlubbelsMax(const ABlubbels: integer): integer;
      {$ENDIF CollectionFiltering}
      procedure ListTestString(const AList: TStrings);
      procedure ListAbcdefg(const AList: TStrings);
      {$IFDEF CollectionSorting}
      procedure SortTestString;
      procedure SortBlubbels;
      procedure SortAbcdefg;
      {$ENDIF CollectionSorting}
      {$IFDEF GUICollection}
      procedure ToListItem(const Item: TListItem);
      procedure ToFilteredListItem(const Item: TListItem);
      {$ENDIF GUICollection}
      property Items[Index: Integer]: TMyCollectionItem read GetItem write SetItem; default;
      {$IFDEF CollectionFiltering}
      property FilteredCount: integer read GetFilteredCount;
      property FilteredItems[Index: Integer]: TMyCollectionItem read GetFilteredItem;
      {$ENDIF CollectionFiltering}
   end;

implementation

uses {$IFDEF CollectionIniOps} IniFiles, {$ENDIF CollectionIniOps}
     Windows;

{$IFDEF CollectionSorting}

{*------------------------------------------------------------------------------
  Returns the list belonging to a collection to allow sorting.

  @param ACollection  Collection to sort
  @return  TList that can be sorted.
-------------------------------------------------------------------------------}
function GetCollectionList(const ACollection: TCollection): TList;
var mMethod: TMethod;
    lMethod: TList absolute mMethod;
    pItemClass: Pointer;
begin
   {$IFNDEF Linux}
   pItemClass := @ACollection.ItemClass;
   inc(Integer(pItemClass), SizeOf(TCollectionItemClass));
   mMethod := TMethod(pItemClass^);
   Result := lMethod;
   {$ENDIF Linux}
end;

{*------------------------------------------------------------------------------
  Comparison of 2 TMyCollectionItem items by TestString for sorting purposes.

  @param item1  Item to be compared
  @param item2  Item to compare against
  @return  Either zero or a negativ or positive value.
-------------------------------------------------------------------------------}
function TMyCollectionItemCompareTestString(item1,item2: pointer): integer;
// Purpose: Comparison of 2 TMyCollectionItem items by TestString for sorting purposes.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   Result := AnsiCompareText(TMyCollectionItem(item1).TestString, TMyCollectionItem(item2).TestString);
end;

{*------------------------------------------------------------------------------
  Comparison of 2 TMyCollectionItem items by Blubbels for sorting purposes.

  @param item1  Item to be compared
  @param item2  Item to compare against
  @return  Either zero or a negativ or positive value.
-------------------------------------------------------------------------------}
function TMyCollectionItemCompareBlubbels(item1,item2: pointer): integer;
// Purpose: Comparison of 2 TMyCollectionItem items by Blubbels for sorting purposes.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   Result := TMyCollectionItem(item1).Blubbels - TMyCollectionItem(item2).Blubbels;
end;

{*------------------------------------------------------------------------------
  Comparison of 2 TMyCollectionItem items by Abcdefg for sorting purposes.

  @param item1  Item to be compared
  @param item2  Item to compare against
  @return  Either zero or a negativ or positive value.
-------------------------------------------------------------------------------}
function TMyCollectionItemCompareAbcdefg(item1,item2: pointer): integer;
// Purpose: Comparison of 2 TMyCollectionItem items by Abcdefg for sorting purposes.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   Result := AnsiCompareText(TMyCollectionItem(item1).Abcdefg, TMyCollectionItem(item2).Abcdefg);
end;

{$ENDIF CollectionSorting}

{ TMyCollectionItem }

{*------------------------------------------------------------------------------
  Assigns properties of one TMyCollectionItem to another. 

  @param Source  Object which properties should be copied.
-------------------------------------------------------------------------------}
procedure TMyCollectionItem.Assign(Source: TPersistent);
// Purpose: Assigns properties of one TMyCollectionItem to another.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   if Source is TMyCollectionItem then with Source as TMyCollectionItem do begin
      Self.FOwner := FOwner;
      Self.FTestString := FTestString;
      Self.FBlubbels := FBlubbels;
      Self.FAbcdefg := FAbcdefg;
   end else inherited Assign(Source);
end;

{*------------------------------------------------------------------------------
  Constructor for TMyCollectionItem 

  @param ACollection  The collection object this TMyCollectionItem is inserted to.
-------------------------------------------------------------------------------}
constructor TMyCollectionItem.Create(ACollection: TCollection);
// Purpose: Constructor for TMyCollectionItem.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   inherited Create(ACollection);
   FOwner := TMyCollectionList(ACollection);
end;

{*------------------------------------------------------------------------------
  Destructor for TMyCollectionItem 
-------------------------------------------------------------------------------}
destructor TMyCollectionItem.Destroy;
// Purpose: Destructor for TMyCollectionItem.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   inherited Destroy;
end;

{*------------------------------------------------------------------------------
  Returns string representing this item. 

  @return  Name of item
-------------------------------------------------------------------------------}
function TMyCollectionItem.GetDisplayName: string;
// Purpose: Returns string representing this item.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   { TODO -oUnknown author -cStart : Make sure to use a proper GetDisplayName }
   Result := FTestString;
   if Result = ''
    then Result := inherited GetDisplayName;
end;

{$IFDEF GUICollection}
{*------------------------------------------------------------------------------
  Fill a TListItem with properties of this TMyCollectionItem.

  @param Item  List item to fill with properties of this TMyCollectionItem.
-------------------------------------------------------------------------------}
procedure TMyCollectionItem.ToListItem(const Item: TListItem);
// Purpose: Fill a TListItem with properties of this TMyCollectionItem.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   while Item.SubItems.Count<2
    do Item.SubItems.Add('');
   { TODO -oUnknown author -cStart : Sort list in your preferred way }
   Item.Caption := FTestString;
   Item.SubItems[0] := FTestString;
   Item.SubItems[1] := IntToStr(FBlubbels);
   Item.SubItems[2] := FAbcdefg;
end;
{$ENDIF GUICollection}

{ TMyCollectionList }

{*------------------------------------------------------------------------------
  Adds a new item of type TMyCollectionItem to list TMyCollectionList.

  @return  Returns the added object of type TMyCollectionItem.
-------------------------------------------------------------------------------}
function TMyCollectionList.Add: TMyCollectionItem;
// Purpose: Adds a new item of type TMyCollectionItem to list TMyCollectionList.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   Result := TMyCollectionItem(inherited Add);
end;

{*------------------------------------------------------------------------------
  Counts all matching TMyCollectionItem.

  @param ATestString  The TestString that should be counted.
  @return  Count of items matching the given TestString.
-------------------------------------------------------------------------------}
function TMyCollectionList.CountTestString(const ATestString: string): integer;
// Purpose: Counts all matching TMyCollectionItem.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var iItem: integer;
begin
   Result := 0;
   for iItem := 0 to Pred(Count) do begin
      if GetItem(iItem).TestString=ATestString
       then Inc(Result);
   end;
end;
{*------------------------------------------------------------------------------
  Counts all matching TMyCollectionItem.

  @param ABlubbels  The Blubbels that should be counted.
  @return  Count of items matching the given Blubbels.
-------------------------------------------------------------------------------}
function TMyCollectionList.CountBlubbels(const ABlubbels: integer): integer;
// Purpose: Counts all matching TMyCollectionItem.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var iItem: integer;
begin
   Result := 0;
   for iItem := 0 to Pred(Count) do begin
      if GetItem(iItem).Blubbels=ABlubbels
       then Inc(Result);
   end;
end;
{*------------------------------------------------------------------------------
  Counts all matching TMyCollectionItem.

  @param AAbcdefg  The Abcdefg that should be counted.
  @return  Count of items matching the given Abcdefg.
-------------------------------------------------------------------------------}
function TMyCollectionList.CountAbcdefg(const AAbcdefg: string): integer;
// Purpose: Counts all matching TMyCollectionItem.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var iItem: integer;
begin
   Result := 0;
   for iItem := 0 to Pred(Count) do begin
      if GetItem(iItem).Abcdefg=AAbcdefg
       then Inc(Result);
   end;
end;

{*------------------------------------------------------------------------------
  Constructor for TMyCollectionList.
-------------------------------------------------------------------------------}
constructor TMyCollectionList.Create;
// Purpose: Constructor for TMyCollectionList.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   inherited Create(TMyCollectionItem);
   {$IFDEF CollectionFiltering}
   SetLength(FFilteredItems,0);
   {$ENDIF CollectionFiltering}
end;

{*------------------------------------------------------------------------------
  Destructor for TMyCollectionList.
-------------------------------------------------------------------------------}
destructor TMyCollectionList.Destroy;
// Purpose: Destructor for TMyCollectionList.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   inherited;
end;

{$IFDEF CollectionIniOps}
{*------------------------------------------------------------------------------
  Loads TMyCollectionList collection from INI file.

  @param Filename  Name of the file to be loaded into collection.
-------------------------------------------------------------------------------}
procedure TMyCollectionList.LoadFromINIFile(const AFilename: string);
// Purpose: Loads TMyCollectionList collection from INI file.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var mif: TMemIniFile;
    slKeys: TStringList;
    iKey: integer;
begin
   Clear;
   mif := TMemIniFile.Create(AFilename);
   slKeys := TStringList.Create;
   mif.ReadSections(slKeys);
   slKeys.Sort;
   for iKey := 0 to Pred(slKeys.Count) do with Add do begin
      FTestString := slKeys[iKey];
      FBlubbels := mif.ReadInteger(slKeys[iKey], 'Blubbels', 0);
      FTestString := mif.ReadString(slKeys[iKey], 'TestString', '');
      FAbcdefg := mif.ReadString(slKeys[iKey], 'Abcdefg', '');
      // FBlubbels := mif.Read(slKeys[iKey], 'Blubbels', '');
   end;
   slKeys.Free;
   mif.Free;
end;

{*------------------------------------------------------------------------------
  Saves TMyCollectionList collection to INI file.

  @param Filename  Name of the file the collection should be saved to.
-------------------------------------------------------------------------------}
procedure TMyCollectionList.SaveToINIFile(const AFilename: string);
// Purpose: Saves TMyCollectionList collection to INI file.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var mif: TMemIniFile;
    slKeys: TStringList;
    item: TMyCollectionItem;
    iKey: integer;
    sKey: string;
begin
   mif := TMemIniFile.Create(AFilename);
   slKeys := TStringList.Create;
   mif.ReadSections(slKeys);
   for iKey := 0 to Pred(slKeys.Count) do begin
      if FindTestString(slKeys[iKey])=nil
       then mif.EraseSection(slKeys[iKey]);
   end;
   slKeys.Free;
   for iKey := 0 to Pred(Count) do begin
      item := GetItem(iKey);
      sKey := item.TestString;
      mif.WriteInteger(sKey, 'Blubbels', item.FBlubbels);
      mif.WriteString(sKey, 'TestString', item.FTestString);
      mif.WriteString(sKey, 'Abcdefg', item.FAbcdefg);
      // mif.Write(sKey, 'Blubbels', item.FBlubbels);
   end;
   mif.UpdateFile;
   mif.Free;
end;
{$ENDIF CollectionIniOps}

{*------------------------------------------------------------------------------
  Returns first TMyCollectionItem matching search parameters.

  @param   ATestString  The contents that is to be searched for.
  @return  Found item that matches TestString, or nil if nothing found.
-------------------------------------------------------------------------------}
function TMyCollectionList.FindTestString(const ATestString: string): TMyCollectionItem;
// Purpose: Returns first TMyCollectionItem matching search parameters.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var iItem: integer;
begin
   Result := nil;
   for iItem := 0 to Pred(Count)
    do if GetItem(iItem).TestString=ATestString then begin
       Result := GetItem(iItem);
       Exit;
    end;
end;
{*------------------------------------------------------------------------------
  Returns first TMyCollectionItem matching search parameters.

  @param   ABlubbels  The contents that is to be searched for.
  @return  Found item that matches Blubbels, or nil if nothing found.
-------------------------------------------------------------------------------}
function TMyCollectionList.FindBlubbels(const ABlubbels: integer): TMyCollectionItem;
// Purpose: Returns first TMyCollectionItem matching search parameters.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var iItem: integer;
begin
   Result := nil;
   for iItem := 0 to Pred(Count)
    do if GetItem(iItem).Blubbels=ABlubbels then begin
       Result := GetItem(iItem);
       Exit;
    end;
end;
{*------------------------------------------------------------------------------
  Returns first TMyCollectionItem matching search parameters.

  @param   AAbcdefg  The contents that is to be searched for.
  @return  Found item that matches Abcdefg, or nil if nothing found.
-------------------------------------------------------------------------------}
function TMyCollectionList.FindAbcdefg(const AAbcdefg: string): TMyCollectionItem;
// Purpose: Returns first TMyCollectionItem matching search parameters.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var iItem: integer;
begin
   Result := nil;
   for iItem := 0 to Pred(Count)
    do if GetItem(iItem).Abcdefg=AAbcdefg then begin
       Result := GetItem(iItem);
       Exit;
    end;
end;

{*------------------------------------------------------------------------------
  Creates a list of all item values.

  @param   AList List to be filled.
-------------------------------------------------------------------------------}
procedure TMyCollectionList.ListTestString(const AList: TStrings);
var iItem: integer;
    item: TMyCollectionItem;
begin
   for iItem := 0 to Pred(Count) do begin
      item := GetItem(iItem);
      if AList.IndexOf(item.TestString)<0
       then AList.Add(item.TestString);
   end;
end;
{*------------------------------------------------------------------------------
  Creates a list of all item values.

  @param   AList List to be filled.
-------------------------------------------------------------------------------}
procedure TMyCollectionList.ListAbcdefg(const AList: TStrings);
var iItem: integer;
    item: TMyCollectionItem;
begin
   for iItem := 0 to Pred(Count) do begin
      item := GetItem(iItem);
      if AList.IndexOf(item.Abcdefg)<0
       then AList.Add(item.Abcdefg);
   end;
end;

{*------------------------------------------------------------------------------
  Returns one TMyCollectionItem by index. 

  @param   Index  Index of item to be retrieved.
  @return  Item of type TMyCollectionItem identified by Index.
-------------------------------------------------------------------------------}
function TMyCollectionList.GetItem(Index: Integer): TMyCollectionItem;
// Purpose: Returns one TMyCollectionItem by index.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   Result := TMyCollectionItem(inherited GetItem(Index));
end;

{*------------------------------------------------------------------------------
  Sets one TMyCollectionItem by index. 

  @param   Index  Index of item to be set.
-------------------------------------------------------------------------------}
procedure TMyCollectionList.SetItem(Index: Integer; Value: TMyCollectionItem);
// Purpose: Sets one TMyCollectionItem by index.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   inherited SetItem(Index, Value);
end;

{$IFDEF CollectionSorting}
{*------------------------------------------------------------------------------
  Sorts TMyCollectionList by TestString.
-------------------------------------------------------------------------------}
procedure TMyCollectionList.SortTestString;
// Purpose: Sorts TMyCollectionList by TestString.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   GetCollectionList(Self).Sort(@TMyCollectionItemCompareTestString);
end;
{*------------------------------------------------------------------------------
  Sorts TMyCollectionList by Blubbels.
-------------------------------------------------------------------------------}
procedure TMyCollectionList.SortBlubbels;
// Purpose: Sorts TMyCollectionList by Blubbels.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   GetCollectionList(Self).Sort(@TMyCollectionItemCompareBlubbels);
end;
{*------------------------------------------------------------------------------
  Sorts TMyCollectionList by Abcdefg.
-------------------------------------------------------------------------------}
procedure TMyCollectionList.SortAbcdefg;
// Purpose: Sorts TMyCollectionList by Abcdefg.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   GetCollectionList(Self).Sort(@TMyCollectionItemCompareAbcdefg);
end;
{$ENDIF CollectionSorting}

{$IFDEF GUICollection}
{*------------------------------------------------------------------------------
  Fills a TListItem with properties of TMyCollectionItem specified by index in TListItem.

  @param   Item  TListItem object to be filled with properties of this TMyCollectionItem
-------------------------------------------------------------------------------}
procedure TMyCollectionList.ToListItem(const Item: TListItem);
// Purpose: Fills a TListItem with properties of TMyCollectionItem specified by index in TListItem.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   if Item.Index<0
    then Exit;
   if Item.Index>=Count
    then Exit;
   GetItem(Item.Index).ToListItem(Item);
end;
{$ENDIF GUICollection}

{$IFDEF CollectionFiltering}
{$IFDEF GUICollection}
{*------------------------------------------------------------------------------
  Fills a TListItem with properties of filtered TMyCollectionItem specified by index in TListItem.

  @param   Item  TListItem object to be filled with properties of this TMyCollectionItem
-------------------------------------------------------------------------------}
procedure TMyCollectionList.ToFilteredListItem(const Item: TListItem);
// Purpose: Fills a TListItem with properties of TMyCollectionItem specified by index in TListItem.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   if Item.Index<0
    then Exit;
   if Item.Index>=Count
    then Exit;
   FilteredItems[Item.Index].ToListItem(Item);
end;
{$ENDIF GUICollection}

{*------------------------------------------------------------------------------
  Adds an item to the list of filtered items.

  @param   Value  Identifies the item to be added to the filtered list.
-------------------------------------------------------------------------------}
procedure TMyCollectionList.AddFilteredItem(Value: TMyCollectionItem);
// Purpose: Adds an item to the list of filtered items.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   SetLength(FFilteredItems,Length(FFilteredItems)+1);
   FFilteredItems[Length(FFilteredItems)-1] := Value;
end;

{*------------------------------------------------------------------------------
  Clears list of filtered items.
-------------------------------------------------------------------------------}
procedure TMyCollectionList.ClearFilterList;
// Purpose: Clears list of filtered items.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   SetLength(FFilteredItems,0);
end;

{*------------------------------------------------------------------------------
  Filters all TMyCollectionItem matching to FilteredItems list.

  @param ATestString  The TestString that should be filtered.
  @return  Count of items matching the given TestString.
-------------------------------------------------------------------------------}
function TMyCollectionList.FilterTestString(const ATestString: string): integer;
// Purpose: Filters all TMyCollectionItem matching to FilteredItems list.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var iItem: integer;
begin
   SetLength(FFilteredItems,0);
   for iItem := 0 to Pred(Count) do begin
      if GetItem(iItem).TestString=ATestString
       then AddFilteredItem(GetItem(iItem));
   end;
   Result := Length(FFilteredItems);
end;
{*------------------------------------------------------------------------------
  Filters all TMyCollectionItem matching to FilteredItems list.

  @param ABlubbels  The Blubbels that should be filtered.
  @return  Count of items matching the given Blubbels.
-------------------------------------------------------------------------------}
function TMyCollectionList.FilterBlubbels(const ABlubbels: integer): integer;
// Purpose: Filters all TMyCollectionItem matching to FilteredItems list.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var iItem: integer;
begin
   SetLength(FFilteredItems,0);
   for iItem := 0 to Pred(Count) do begin
      if GetItem(iItem).Blubbels=ABlubbels
       then AddFilteredItem(GetItem(iItem));
   end;
   Result := Length(FFilteredItems);
end;

{*------------------------------------------------------------------------------
  Filters all TMyCollectionItem matching a minimum in FilteredItems list.

  @param ABlubbels  The minimum value for Blubbels.
  return  Count of items matching the given Blubbels.
-------------------------------------------------------------------------------}
function TMyCollectionList.FilterBlubbelsMin(const ABlubbels: integer): integer;
// Purpose: Filters all TMyCollectionItem matching a minimum in FilteredItems list.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var iItem: integer;
begin
   SetLength(FFilteredItems,0);
   for iItem := 0 to Pred(Count) do begin
      if GetItem(iItem).Blubbels>=ABlubbels
       then AddFilteredItem(GetItem(iItem));
   end;
   Result := Length(FFilteredItems);
end;

{*------------------------------------------------------------------------------
  Filters all TMyCollectionItem matching a maximum in FilteredItems list.

  @param ABlubbels  The maximum value for Blubbels.
  return  Count of items matching the given Blubbels.
-------------------------------------------------------------------------------}
function TMyCollectionList.FilterBlubbelsMax(const ABlubbels: integer): integer;
// Purpose: Filters all TMyCollectionItem matching a maximum in FilteredItems list.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var iItem: integer;
begin
   SetLength(FFilteredItems,0);
   for iItem := 0 to Pred(Count) do begin
      if GetItem(iItem).Blubbels<=ABlubbels
       then AddFilteredItem(GetItem(iItem));
   end;
   Result := Length(FFilteredItems);
end;
{*------------------------------------------------------------------------------
  Filters all TMyCollectionItem matching to FilteredItems list.

  @param AAbcdefg  The Abcdefg that should be filtered.
  @return  Count of items matching the given Abcdefg.
-------------------------------------------------------------------------------}
function TMyCollectionList.FilterAbcdefg(const AAbcdefg: string): integer;
// Purpose: Filters all TMyCollectionItem matching to FilteredItems list.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
var iItem: integer;
begin
   SetLength(FFilteredItems,0);
   for iItem := 0 to Pred(Count) do begin
      if GetItem(iItem).Abcdefg=AAbcdefg
       then AddFilteredItem(GetItem(iItem));
   end;
   Result := Length(FFilteredItems);
end;

{*------------------------------------------------------------------------------
  Returns one specific filtered TMyCollectionItem.

  @param Index of item from filtered list.
  @return  Returns TMyCollectionItem matching the given Index.
-------------------------------------------------------------------------------}
function TMyCollectionList.GetFilteredItem(Index: Integer): TMyCollectionItem;
// Purpose: Returns one specific filtered TMyCollectionItem.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   Result := FFilteredItems[Index];
end;

{*------------------------------------------------------------------------------
  Returns number of filtered TMyCollectionItem.

  @return  Returns number of filtered TMyCollectionItem.
-------------------------------------------------------------------------------}
function TMyCollectionList.GetFilteredCount: integer;
// Purpose: Returns number of filtered TMyCollectionItem.
// Date:    2007-04-25 (Function created by CollectionCodeMaker)
begin
   Result := Length(FFilteredItems);
end;
{$ENDIF CollectionFiltering}

end.