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
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
 Download this web site as a Windows program.

Development Boards at very low prices with free postage.


 
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 2002 - 2014. All rights reserved.  |  Contact the author  |  Home Page