home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Calmira / Src / UTILS / OBJLIST.PAS < prev    next >
Pascal/Delphi Source File  |  1997-02-15  |  1KB  |  55 lines

  1. {*********************************************************}
  2. {                                                         }
  3. {    Calmira System Library 1.0                           }
  4. {    by Li-Hsin Huang,                                    }
  5. {    released into the public domain January 1997         }
  6. {                                                         }
  7. {*********************************************************}
  8.  
  9. unit Objlist;
  10.  
  11. { TObjectList is a simple descendant of TList that assumes each item
  12.   is a descendant of TObject.  It defines two new methods :
  13.  
  14.   ClearObjects calls Free for each pointer before clearing the list.
  15.   FreeObject calls Free for a list item before calling Delete.
  16.  
  17.   Destroy is overriden to free all objects.
  18. }
  19.  
  20. interface
  21.  
  22. uses Classes;
  23.  
  24. type
  25.  
  26. TObjectList = class(TList)
  27. public
  28.   destructor Destroy; override;
  29.   procedure ClearObjects;
  30.   procedure FreeObject(i: Integer);
  31. end;
  32.  
  33. implementation
  34.  
  35. destructor TObjectList.Destroy;
  36. begin
  37.   ClearObjects;
  38.   inherited Destroy;
  39. end;
  40.  
  41. procedure TObjectList.ClearObjects;
  42. var i: Integer;
  43. begin
  44.   for i := 0 to Count-1 do TObject(List^[i]).Free;
  45.   Clear;
  46. end;
  47.  
  48. procedure TObjectList.FreeObject(i: Integer);
  49. begin
  50.   TObject(Items[i]).Free;
  51.   Delete(i);
  52. end;
  53.  
  54. end.
  55.