Delphi ShortInt ToString Helper with constant

I have some constants in a separate unit, I can not do .ToString for these constants if the type is ShortInt (<128).

Example: Create a block and add:

const abc = 127; 

Create TForm and in FormShow do:

 Edit1.Text := abc.tostring; 

Do you know why this did not work? Enter a record type, object or class ..

It works if the constant is in one block.

+6
source share
1 answer

I can reproduce this with the following minimal example

Program1.dpr

 program Project1; {$APPTYPE CONSOLE} uses System.SysUtils, Unit1 in 'Unit1.pas'; begin Writeln(abc.ToString); end. 

Unit1.pas

 unit Unit1; interface const abc = 127; implementation end. 

This is a clear compiler error. You can work around the issue with a hint of an inelegant type as follows:

 const abc = Shortint(127); 

This tells me that when there is no type hint, the compiler sees 127 as something other than Shortint . I'm not quite sure that, though, because I do not see the inside of the compiler.

Submit a bug report to Embarcadero.

+4
source

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


All Articles