ESubstringInPlaceError Exception

Exception→ESubstringError→ESubstringInPlaceError

type ESubstringInPlaceError = class(ESubstringError);

A write after the text on characters the string does not own alone.

Append and AppendInt write after the text, and ToPChar writes a #0 there. On characters shared with another string or adopted from one, that would change what the other sees, so Substring raises instead of copying. MakeUnique gives the string its own characters first.

Examples

Appending to an adopted string raises; MakeUnique copies it first.

delphi
uses Substr;

procedure Example;
var Text: string;
    s: Substring;
    Raised: Boolean;
begin
    Text := 'abc';
    s.Adopt(Text);
    Raised := False;
    try
        s.Append('d');
    except
        on ESubstringInPlaceError do Raised := True;
    end;
    Assert(Raised);
    s.MakeUnique;
    s.Append('d');
    Assert(s = 'abcd');
    Assert(Text = 'abc');
end;