DelphiBasics
setstring
Procedure
Copies characters from a buffer into a string System unit
 procedure setstring(var TargetString string; BufferPointer PChar; Length Integer);
Description
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
FillCharFills out a section of storage with a fill character or byte value
SetLengthChanges the size of a string, or the size(s) of an array
StringOfCharCreates a string with one character repeated many times
 Download this web site as a Windows program.




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

begin
  // 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);
end;
Show full unit code
  target now = ABCDE
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page