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 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.

See Also

String Keyword
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset