Data Types in Delphi XE3, Win32 and Win64


The Delphi has been out of the mainstream programming languages for a while. It is not because it is not good. There are many reasons that it is not so popular than before. The latest Delphi compiler, XE3, being released in 2012 by Embarcadero, has been considered the best Delphi compilers ever, similar to Delphi 7 in the past.

The Delphi has supported 64-bit in XE2 and it is now very easy to write once and compile for 32-bit windows, 64-bit windows, or even MAC, Android. For example, you can add a new platform in the project manager. The delphi produces truly native code on all platforms, and the most shining aspect about the compiler is its compiling speed, i.e. within a few seconds thousand lines of code.

pg Data Types in Delphi XE3, Win32 and Win64 beginner compiler delphi implementation object pascal programming languages windows

We can test the data types using the same program below, to see the difference between 32-bit and 64-bit code generated by Delphi XE3.

program Project4;

{$APPTYPE CONSOLE}

{$R *.res}

begin
{$IFDEF WIN32}
  Writeln('Win32 Data Types');
{$ENDIF}
{$IFDEF WIN64}
  Writeln('Win64 Data Types');
{$ENDIF}
  Writeln('Floating:');
  Writeln(#9, 'Single', #9, #9, SizeOf(Single));
  Writeln(#9, 'Double', #9, #9, SizeOf(Double));
  Writeln(#9, 'Real', #9, #9, SizeOf(Real));
  Writeln(#9, 'Extended', #9, SizeOf(Extended));
  Writeln(#9, 'Currency', #9, SizeOf(Currency));
  Writeln(#9, 'Read48', #9, #9, SizeOf(Real48));
  Writeln(#9, 'Comp', #9, #9, SizeOf(Comp));
  Writeln('Signed Integer:');
  Writeln(#9, 'ShortInt', #9, SizeOf(ShortInt));
  Writeln(#9, 'SmallInt', #9, SizeOf(SmallInt));
  Writeln(#9, 'LongInt', #9, #9, SizeOf(LongInt));
  Writeln(#9, 'Integer', #9, #9, SizeOf(Integer));
  Writeln(#9, 'Int64', #9, #9, SizeOf(Int64));
  Writeln(#9, 'NativeInt', #9, SizeOf(NativeInt));
  Writeln('Unsigned Integer:');
  Writeln(#9, 'Byte', #9, #9, SizeOf(Byte));
  Writeln(#9, 'Word', #9, #9, SizeOf(Word));
  Writeln(#9, 'LongWord', #9, SizeOf(LongWord));
  Writeln(#9, 'Cardinal', #9, SizeOf(Cardinal));
  Writeln(#9, 'UInt64', #9, #9, SizeOf(UInt64));
  Writeln(#9, 'NativeUInt', #9, SizeOf(NativeUInt));
  Readln;
end.

We can check the compiler directives {$WIN32} and {$WIN64} that control the code for 32 and 64 bit respectively during compilation time. The other way is to check the size of the pointer, being 4 for 32-bit and 8 for 64-bit. This can be done similarly in compilation time using {$IF SizeOf(Pointer)=4} or a simple if statement that is executed during runtime.

When the program compiles to 32-bit, it produces the following output.
win32 Data Types in Delphi XE3, Win32 and Win64 beginner compiler delphi implementation object pascal programming languages windows

When the program compiles to 64-bit, it produces the following output.
win64 Data Types in Delphi XE3, Win32 and Win64 beginner compiler delphi implementation object pascal programming languages windows

If you look carefully at the difference, you will see that only a few data types differ. For example, the extended type in Delphi 32-bit is 10 bytes while in 64-bit, it is an alias of double type. The nativeint and nativeuint are signed and unsigned integers. Both are 4-byte on 32-bit and 8 byte on 64-bit. All the other number types such as integer, int64 are the same on both 32-bit and 64-bit, which makes it easy to port the 32-bit applications to 64-bit. Sometimes, all you have to do is to re-build the application targeting 64-bit windows.

Delphi is now a truly RAD (Rapid Application Development) tool for 32-bit windows, 64-bit windows, MAC, and even iOS.  I can see the Embarcadero really takes seriously the Delphi tool otherwise, this excellent tool might have been destroyed by Borland.

Long live delphi and long live object pascal!

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
673 words
Last Post: Stackoverflow: Why doesn't the optimizer eliminate High in a loop?
Next Post: Get Started: Unicode in Delphi XE3

The Permanent URL is: Data Types in Delphi XE3, Win32 and Win64

Leave a Reply