Home  |  Delphi .net Home  |  system.String  |  Copy Method
Copy  
Method  
Creates a new instance of String with the same value as a specified String.
String Class
system NameSpace
CF1.  Function Copy ( Source : String; ) : String;
CF : Methods with this mark are Compact Framework Compatible
Description
The Source string object is copied to the target (result) string. The target is a new string rather than a reference to the original string. This means that any updates to the original source string are isolated to that string.
Microsoft MSDN Links
system
system.String
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  strA, strB : String;

begin
  strA := 'First';
  strB := 'Second';

  Console.WriteLine('Before copy');
  Console.WriteLine('strA = ' + strA);
  Console.WriteLine('strB = ' + strB);

  strB := System.String.Copy(strA);

  Console.WriteLine('After copy of strA to strB');
  Console.WriteLine('strA = ' + strA);
  Console.WriteLine('strB = ' + strB);

  strA := 'First updated';

  Console.WriteLine('After update of strA');
  Console.WriteLine('strA = ' + strA);
  Console.WriteLine('strB = ' + strB);

  Console.ReadLine;
end.
Show full unit code
  Before copy
  strA = First
  strB = Second
  After copy of strA to strB
  strA = First
  strB = First
  After update of strA
  strA = First updated
  strB = First
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author