TSubstringList.Strings Property

property Strings[const Index: Integer]: Substring read GetItem write Put; default;

Item Index (0..Count - 1), read in place: no memory is taken and no character copied.

#NameDescription
1Index

The item's index, 0..Count - 1.

Returns: Substring

Remarks:

The Substring reads the item's characters where they are. It reads the item until the item is written or deleted, or until Capacity is set or the list shrunk; after that it dangles, as designed, as a Substring view of a freed string does - held in a local or stored in another item alike. s[i] :=, UpperCaseAscii and LowerCaseAscii on it change the item; ToPChar gives a text the list wrote, terminated, in place. Writing List[Index] := S stores S in the item (Put). An Index outside the list raises EStringListError.

Examples

An item read in place and changed through it.

uses Substr;

procedure Example;
var List: TSubstringList;
    s: Substring;
begin
    List := TSubstringList.Create(4);
    try
        List.Add('hello');
        s := List[0];
        Assert(s.ToPChar[5] = #0);
        s.UpperCaseAscii;
        Assert(List[0] = 'HELLO');
    finally
        List.Free;
    end;
end;
See Also: TSubstringList.Items, TSubstringList.Put, TSubstringList.GetEnumerator