Ignore:
Timestamp:
Jun 2, 2013, 6:59:07 PM (11 years ago)
Author:
chronos
Message:
  • Fixed: Components now have list of childs and free them on destruction.
  • Fixed: Memory leaks.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • os/trunk/Xvcl/Xvcl.Generics.pas

    r5 r7  
    3333    function Compare(Item1, Item2: T): Integer;
    3434    procedure Exchange(Index1, Index2: Integer);
     35    procedure Clear;
    3536    property Count: Integer read FCount write SetCount;
    3637    property Items[Index: Integer]: T read GetItem write SetItem; default;
     38  end;
     39
     40  TObjectList<T: class> = class(TList<T>)
     41    OwnsObjects: Boolean;
     42    constructor Create; virtual;
     43    destructor Destroy; override;
    3744  end;
    3845
     
    6168  FItems[Count - 1] := Item;
    6269  Result := Count - 1;
     70end;
     71
     72procedure TList<T>.Clear;
     73begin
     74  Count := 0;
    6375end;
    6476
     
    149161end;
    150162
     163{ TObjectList<T> }
     164
     165constructor TObjectList<T>.Create;
     166begin
     167  OwnsObjects := True;
     168end;
     169
     170destructor TObjectList<T>.Destroy;
     171var
     172  I: Integer;
     173begin
     174  if OwnsObjects then
     175  for I := 0 to Count - 1 do
     176    TObject(FItems[I]).Destroy;
     177  Clear;
     178  inherited;
     179end;
     180
    151181end.
Note: See TracChangeset for help on using the changeset viewer.