title: Delphi 2007 and XE2: Using NativeInt
body: <p>Since Delphi XE2, NativeInt has new meaning.  At 32 bits runtime, NativeInt is 32 bits integer.  At 64 bits runtime, NativeInt is 64 bits integer.</p>
  
  <p>I have some source files that use third party DLL (both 32 and 64 bits).  These DLL use 32 and 64 bits integer in both 32 and 64 platform respectively.</p>
  
  <p>These source files works in Delphi 2007 - Delphi XE2 32 bits platform without problem:</p>
  
  <p>e.g.:</p>
  
  <pre><code>function Test: Integer;
  </code></pre>
  
  <p>When I attempt to migrate those source files to Delphi XE2 64 bits platform, the above function no longer works as it require 64 bits integer.  In order to make the source works for both 32/64 platforms, I change to </p>
  
  <pre><code>function Test: NativeInt;
  </code></pre>
  
  <p>And it works.</p>
  
  <p>However, the declaration doesn't work in Delphi 2007 as Delphi 2007 treat NativeInt as 64 bits integer: SizeOf(NativeInt) = 8</p>
  
  <p>I may solve the problem by using conditional directive RtlVersion or CompilerVersion to </p>
  
  <pre><code>function Test: {$if CompilerVersion&lt;=18.5}Integer{$else}NativeInt{$ifend};
  </code></pre>
  
  <p>But that would be tedious as there are many declaration in source files.</p>
  
  <p>Is there a better ways to make the source files work in Delphi 2007-XE2 win32 and XE2 win64 platform?</p>