This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 1st, 2011  |  syntax: Delphi  |  size: 0.70 KB  |  views: 66  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. program Project26;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses SysUtils;
  6.  
  7. var a, b: array of string;
  8.  
  9. begin
  10.   SetLength(a,1);
  11.   a[0] := IntToStr(Random(1)); // making sure I'm not assigning a constant string
  12.   WriteLn('StringRefCount(a[0])=', StringRefCount(a[0])); // Displays "2"
  13.   SetLength(b,1);
  14.   Move(a[0], b[0], SizeOf(Pointer)); // "Move" the memory
  15.   WriteLn('StringRefCount(a[0]) after Move =', StringRefCount(a[0])); // Displays "2" - wrong, because we now have +1 references to the same string
  16.   SetLength(a,0); // Will actually free the string
  17.  
  18.   WriteLn('StringRefCount(b[0]) after SetLength(a,0) =', StringRefCount(b[0])); // Displays "1" - wrong, because that means the string
  19.  
  20.   ReadLn;
  21. end.
clone this paste RAW Paste Data