System.SetString

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure SetString(var S: String; Buffer: PChar; Length: Integer);

Properties

Type Visibility Source Unit Parent
procedure public System.pas System System

Description

Sets the contents and length of the given string.

In Delphi code, SetString sets the contents and length of the given string variable to the block of characters given by the Buffer and Length parameters.

For a short string variable, SetString sets the length indicator character (the character at S[0]) to the value given by Length and then, if the Buffer parameter is not nil, copies Length characters from Buffer into the string, starting at S[1]. For a short string variable, the Length parameter must be a value from 0 through 255.

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

See Also

Code Examples