Copies characters from a buffer into a string System unit
 procedure SetString ( var TargetString : string; BufferPointer : PChar; Length : Integer ) ;
The SetString procedure sets the length of TargetString to Length before copying that number of characters from the buffer referenced by BufferPointer.
The length is only set when the string is not a ShortString. In fact, the string is reallocated - the TargetString reference is then set to point to this new string.
Related commands
FillChar Fills out a section of storage with a fill character or byte value
SetLength Changes the size of a string, or the size(s) of an array
StringOfChar Creates a string with one character repeated many times
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : A simple example
  target : string;
  source : array[1..5] of Char;
  srcPtr : PChar;
  i      : Integer;

  // Fill out the character array
  for i := 1 to 5 do
    source[i] := Chr(i+64);

  // Copy these characters to a string
  srcPtr := Addr(source);
  SetString(target, srcPtr, 5);

  // Show what we have got
  ShowMessage('target now = '+target);
Show full unit code
   target now = ABCDE
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Contact the author  |  Home Page