[fpc-pascal] Format and Cardinal

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Feb 10 13:32:26 CET 2016


Felipe Monteiro de Carvalho wrote on Wed, 10 Feb 2016:

> Why does this trigger an range check exception:
>
> var
>   lNum: Cardinal;
>   lStr: string;
> begin
>   lNum := High(Cardinal);
>   lStr := Format('Num=%u', [lNum]);
>
> Format doesn't support integer numbers above High(Integer) ?

Array of const supports longint, int64 and qword, but no cardinal  
(Delphi compatibility, and adding it would also mean that all callee  
side code for array of const would have to be adapted to deal with  
vtCardinal). Cardinal is passed as longint and not as int64, again for  
Delphi compatibility and because existing code may behave unexpectedly  
should this be changed.

In Delphi modes, for Delphi compatibility, we don't perform range  
checking when passing a cardinal to an array of const. In FPC modes,  
we do.

> I really need to use IntToStr?

That, or typecast the cardinal either to longint or int64, or locally  
disable range checking.


Jonas



More information about the fpc-pascal mailing list