Some Delphi users even do not know the existence of the
SetString function.
As stated by the official documentation:
procedure SetString(var S: String; Buffer: PChar; Length: Integer);For a long string variable, SetString sets S to reference a newly allocated string of the given length. If the Buffer parameter is not nil, SetString then copies Len characters from Buffer into the string; otherwise, the content of the new string is left uninitialized. If there is not enough memory available to create the string, an EOutOfMemory exception is raised. Following a call to SetString, S is guaranteed to reference a unique string (a string with a reference count of one).
Some have
noticed that in our libraries, I sometimes use SetString
instead of SetLength.
When the string is already allocated, it could be faster to use
SetString, if you are sure that you will overwrite the string
content.
