TSubstringList.OwnsObjects Property

property OwnsObjects: Boolean read FOwnsObjects write FOwnsObjects;

Whether deleting an item, Clear and Free free the items' objects.

Returns: Boolean

Examples

Deleting an item frees its object.

uses Substr;

procedure Example;
var Owner, Inner: TSubstringList;
    Live: NativeInt;
begin
    Owner := TSubstringList.Create(1);
    try
        Owner.OwnsObjects := True;
        Inner := TSubstringList.Create(1);
        Live := Substring.ThreadStats.LiveBlocks;
        Inner.Add(Substring.Create('x', 600));
        Owner.AddObject('inner', Inner);
        Assert(Substring.ThreadStats.LiveBlocks = Live + 1);
        Owner.Delete(0);
        Assert(Substring.ThreadStats.LiveBlocks = Live);
    finally
        Owner.Free;
    end;
end;
See Also: TSubstringList.Objects, TSubstringList.Delete, TSubstringList.Clear