title: Delphi 64-bit: finding incorrect casts?
body: <p>I'm working on adapting a large Delphi code base to 64-bits. In many cases there are lines where pointers are casted to/from 32-bit values similar to this:</p>
  
  <pre><code>var
    p1,p2 : pointer;
  begin
    inc(Integer(p1),10);
    p2 := Pointer(Integer(p1) + 42);
  </code></pre>
  
  <p>Where I can find these casts I have replaced them with NativeInt-casts instead to make them correct in 64-bit mode.</p>
  
  <p>However I'm not sure I have found them all. Sometimes the casts are more subtle so just text-searching for the string "integer(" is not sufficient either.</p>
  
  <p>Since the "integer(" casts will fail in 64-bit if the pointer value is above the range of integer type I have an idea: what if I could force the memory manager to allocate memory above 4gb (so the pointer values are using more than 32-bits)? Then I would get runtime errors and can more easily find the casts that are wrong. Is this possible? Or can anyone recommend some other technique?</p>