Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 438
kludg Avatar asked Dec 04 '22 23:12

kludg


1 Answers

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.

like image 176
dthorpe Avatar answered Dec 15 '22 12:12

dthorpe