UniqueString Procedure
The UniqueString
procedure ensures that
Str
has a reference count of one. If
Str
has no other references,
UniqueString
leaves it alone; otherwise,
UniqueString
allocates a new copy of the string
and assigns that unique copy to
Str
.
UniqueString
is a real procedure.
You do not usually need to call UniqueString
.
Delphi uses copy-on-write semantics for strings, so if you have
multiple references to a string and you modify the string through one
reference, Delphi automatically creates a unique string to modify, so
the other references continue to refer to the original string.
If you cast a string
to PChar
,
Delphi also ensures that the PChar
points to a
unique instance of the string. If you modify the string through the
PChar
pointer, the other references to the
original string are safe.