Delphi c-style hexadecimals - undocumented function?

I accidentally noticed that the following code

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

OK in Delphi 2009. By the way, this function helped me extract hexadecimal constants from the C header file.

I wonder if this function can be used, or will the function be “fixed” in future versions?

+4
source share
2 answers

This is a feature and you can rely on it. One of the philosophical changes that occurred in the evolution of Turbo Pascal in Delphi was the recognition that Delphi lives in a world dominated by C, and it can be obtained by gracefully accepting or tolerating C-isms, than ignoring them and forcing the Delphi developer to figure it out. Interaction with C ++ Builder, as mentioned by Rob, was a factor, but there was also the fact that Delphi was designed first for Windows, and Windows has many C language artifacts in the Windows API.

I think the term “impedance mismatch” can be used here — it was simple enough to eliminate the impedance mismatch between the Delphi hex processing and the “rest of the world”, so we did it.

+12
source

Recall that Delphi RTL is also used by C ++ Builder. The documentation does not say in detail what exactly means that StrToInt accepts "decimal or hexadecimal notation." You can confidently expect StrToInt continue accepting C-style rooms.

Val takes the same input as Read (because they all call the System._ValLong call).

+4
source

Source: https://habr.com/ru/post/1339868/


All Articles