TSubstringList.Resize Method

procedure Resize(const NewCapacity: Integer);

Sets Capacity to NewCapacity, any size, rounded up to a multiple of 128 and at least 128, keeping the items that fit; setting Capacity keeps none.

#NameDescription
1NewCapacity

The number of items to hold afterwards, 0 or more.

Result: stored in self (calling object)

Remarks:

Below Count the items from NewCapacity on are deleted, as Substring.Resize cuts a text; every item kept keeps its index and its text, and an item that reads an item's characters still reads them. Growing moves no item; shrinking moves as few as possible, as Compact does. An item that reads characters no item holds any more - a deleted item's - is left as it is and dangles, as after Delete. Below 0 it raises EStringListError.

Examples

Growing and shrinking a list.

uses Substr;

procedure Example;
var List: TSubstringList;
begin
    List := TSubstringList.Create;
    try
        List.Add('a');
        List.Resize(1000);
        Assert((List.Capacity = 1024) and (List[0] = 'a'));
        List.Resize(1);
        Assert((List.Capacity = 128) and (List.Count = 1) and (List[0] = 'a'));
    finally
        List.Free;
    end;
end;

An item that reads another item still reads it.

uses Substr;

procedure Example;
var List: TSubstringList;
begin
    List := TSubstringList.Create(2);
    try
        List.Add('kept');
        List.Add('x');
        List[1] := List[0];
        List.Resize(1000);
        Assert((List[1] = 'kept') and (List[1].Data = List[0].Data));
    finally
        List.Free;
    end;
end;
See Also: TSubstringList.Capacity, TSubstringList.Expand, TSubstringList.Compact