title: Integer to string cast, Delphi typecast
body: <p>While doing maintenance work in Delphi I ran into some code that I don't understand. I wrote a simple console app to help me think this through but I am still confused. If you look at the attached code you will see that I've only put 1 comment in it. That is the location of my question. </p>
  
  <p>I thought that maybe the value being put into X might be the string's address, or maybe the bit values of each (Unicode) char in the string were used to arrive at the value in X however if you run the program multiple times the value of X appears to be random on each iteration.</p>
  
  <p>Any adult supervision would be appreciated, thanks.</p>
  
  <pre><code>program OrdinalProject;
  {$APPTYPE CONSOLE}
  {$R *.res}
  uses
    System.SysUtils;
  var
    A : string;
    B : ^string;
    X : integer;
  begin
    A := 'ABCD';
    WriteLn(Format('Content of A = %s',[A]));
    WriteLn(Format('Address of A = %p',[@A]));
    WriteLn('');
  
    B := @A;
    WriteLn(Format('Content of B = %p',[B]));
    WriteLn(Format('Address of B = %p',[@B]));
    WriteLn('');
  
    X := integer(A); // What is going on here and why doesn't this fail?
    WriteLn(Format('Content of X = %d',[X]));
    WriteLn(Format('Address of X = %p',[@X]));
    Readln;
  end.
  </code></pre>
  
  <p>Thank you for the responses! I understand this now.</p>