procedure Adopt(const Src: string); overload;
Views all of Src's characters without copying them.
| # | Name | Description |
|---|---|---|
| 1 | Src | The string viewed; it must live unchanged while the view is used. |
Result: stored in self (calling object)
Remarks:
The characters stay Src's (IsExternal), and the view is valid while Src lives unchanged. s[i] :=, UpperCaseAscii and LowerCaseAscii write into Src's characters, which every string that shares them sees; Append and AppendInt raise ESubstringInPlaceError. Adopt is the one operation that adopts a string: every other conversion copies.
Examples
An adopted string changes where it is.
uses Substr;
procedure Example;
var Text: string;
s: Substring;
begin
Text := 'one,two';
UniqueString(Text);
s.Adopt(Text);
Assert(s.IsExternal);
s.UpperCaseAscii;
Assert(Text = 'ONE,TWO');
end;
See Also: Substring.Subrange, Substring.Subrange