Search code examples
delphidelphi-2009hex

C-style hexadecimals in Delphi - undocumented feature?


I noticed by chance that the following code

var
  I: Integer;

begin
  I:= StrToInt('0xAA');
  ShowMessage(IntToStr(I));  // shows 170 = $AA
end;

is OK in Delphi 2009. BTW the feature helped me to extract hexadecimal constants from C header file.

I wonder is it OK to use the feature or the feature is about to be "fixed" in future versions?


Solution

  • It's a feature, and you can rely on it. One of the philosophical changes that occurred in the evolution of Turbo Pascal into Delphi was the acknowledgment that Delphi lives in a C-dominated world and there was more to be gained by gracefully accepting or tolerating C-isms than ignoring them and forcing the Delphi developer to sort it out. Interop with C++ Builder as mentioned by Rob was a factor, but so was the fact that Delphi was designed first for Windows, and Windows has a lot of C language artifacts in the Windows API.

    I think the term "impedance mismatch" may apply here - it was simple enough to remove the impedance mismatch between Delphi hex handling and "Rest of World", so we did.