TSubstringList.Exchange Method

procedure Exchange(const Index1, Index2: Integer);

Swaps items Index1 and Index2.

#NameDescription
1Index1

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

2Index2

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

Result: stored in self (calling object)

Remarks:

An index outside the list raises EStringListError.

Examples

No text moves: a view of an item still reads it.

uses Substr;

procedure Example;
var List: TSubstringList;
    s: Substring;
begin
    List := TSubstringList.Create(2);
    try
        List.Add('a');
        List.Add('b');
        s := List[0];
        List.Exchange(0, 1);
        Assert((List[0] = 'b') and (List[1] = 'a'));
        Assert(s.Data = List[1].Data);
    finally
        List.Free;
    end;
end;
See Also: TSubstringList.Move, TSubstringList.Sort, TSubstringList.Sort