[Lazarus] Typecast set to byte in mode OBJFPC

Jürgen Hestermann juergen.hestermann at gmx.de
Wed Dec 31 17:09:22 CET 2014


Am 2014-12-31 um 16:55 schrieb Joost van der Sluis:
> On 12/31/2014 04:40 PM, Jürgen Hestermann wrote:
>> type FlagType        = (Flag1,Flag2);
>>           FlagSetType   = set of FlagType;
>> var i : SizeInt;
>>        S : FlagSetTyp;
>>
>> S := [Flag1];
>> i := byte(S); // <---- Error "illegal type conversion"
>
> i := ord(S); ?
>
> But it's still invalid, though. A set can contain more then 32 items, and then your conversion does not hold anymore.
>

Yes, in DELPHI mode I get an error at compile time when
the set is declared larger than a byte which is ok
because I can then change all byte(S) calls.

But as already written in another mail I found that
i := SizeInt(S) works (is accepted by the compiler).
But I am not sure, whether the result is the same.
I use the typecasted integer values as an index into
an array which is declared like this:

FileStatistikArrayTyp = array[0..(1 shl (ord(High(FlagSetType))+1))-1] of ...; // 0..2^n-1

I don't know whether the typecasted set still starts with zero.




More information about the Lazarus mailing list