[fpc-devel] Gaps in a non-contiguous enum
juha.manninen62 at gmail.com
Tue Aug 16 08:43:29 CEST 2022
On Thu, Aug 11, 2022 at 9:37 PM Martin Frb via fpc-devel <
fpc-devel at lists.freepascal.org> wrote:
> fpc code is still "unexpected".
> It takes into account the MinValue
> type TMyEnum = (a=5, b=7);
> GetEnumName(pt, 5) // a
> GetEnumName(pt, 6) // b // should be 7
> if it is just the nth name, then it should start at 0 (or if needs be at
And function GetEnumValue() is buggy.
This was noticed when testing the original Lazarus enum property editor bug.
A little modified enum :
TFruitMore = (fmApple=1, fmOrange=3, fmBanana=5, fmGrapes, fmPear);
I := GetEnumValue(EnumType, 'fmBanana'); // Returns 3
I := GetEnumValue(EnumType, 'fmGrapes'); // Returns 4 which is an
Looking at the source of GetEnumValue() the reason is clear.
It increments Count one by one while it should take the gaps into account.
While (Result=-1) and (PByte(PS)^<>0) do
If ShortCompareText(PS^, sName) = 0 then
Where are the ordinal values for enums stored? They are not in TTypeData.
I wanted to fix this right away but I have no idea how.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-devel