Name
UniqueString Procedure
Syntax
procedure UniqueString(var Str: string);
Description
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.
Tips and Tricks
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
stringtoPChar, Delphi also ensures that thePCharpoints to a unique instance of the string. If you modify the string through thePCharpointer, the other references to the original string are safe.
See Also
| String Keyword |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access