TObjects = class(TObject)
private
FItems: TList;
function GetCount: Integer;
function GetItem(Index: Integer): TObject;
public
constructor Create; virtual;
destructor Destroy; override;
procedure Clear;
procedure Delete(Index: Integer);
procedure Append(Item: TObject);
procedure Insert(Index: Integer; Item: TObject);
property Count: Integer read GetCount;
property Items[Index: Integer]: TObject read GetItem;
end;
{ TObjects }
constructor TObjects.Create;
begin
inherited Create;
FItems := TList.Create;
end;
destructor TObjects.Destroy;
begin
Self.Clear;
FItems.Free;
inherited Destroy;
end;
procedure TObjects.Clear;
var
i: Integer;
begin
for i := FItems.Count - 1 downto 0 do
Self.Delete(i);
end;
procedure TObjects.Delete(Index: Integer);
var
Temp: TObject;
begin
if (Index > FItems.Count - 1) or
(Index < 0) then exit;
Temp := Self.Items[Index];
FItems.Delete(Index);
if Assigned(Temp) then
FreeAndNil(Temp);
end;
procedure TObjects.Insert(Index: Integer; Item: TObject);
begin
if (Index > FItems.Count - 1) or
(Index < 0) then exit;
FItems.Insert(Index, Item);
end;
procedure TObjects.Append(Item: TObject);
begin
FItems.Add(Item);
end;
function TObjects.GetCount: Integer;
begin
Result := FItems.Count;
end;
function TObjects.GetItem(Index: Integer): TObject;
begin
Result := TObject(FItems.Items[Index]);
end;