[fpc-pascal] Enum property can't be published
Ondrej Pokorny
lazarus at kluug.net
Tue Sep 27 12:31:39 CEST 2022
Am 27.09.2022 um 11:22 schrieb Hairy Pixels via fpc-pascal:
>> On Sep 27, 2022, at 4:17 PM, Marco van de Voort via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>>
>> 3.2.2 compiles without warnings, 3.3.1 (i386-win32 from 17 sept:)
>>
>> ptt.pp(14,44) Warning: This property will not be published
>>
>> Possibly enums with assigned values (which can have gaps) are not safe to publish, and this was only now noted?
> I must have missed that.
>
> What’s a good solution here? It looks like the code needs these enums to be 1 indexed, otherwise they are all in order with no gaps. If I could publish those and just do a +1 first that would work.
Publishing enums with gaps didn't work in 3.2.2, even if they compiled.
This bug has been fixed.
I can think of these 2 solutions:
1.) Add "unused" enum values to the enum:
TMyEnum = (meOne = 1, meTwo, meThree, meFive = 5);
will become:
TMyEnum = (meUnused1, meOne, meTwo, meThree, meUnused2, meFive);
2.) publish their ordinal value
public
property MyEnum: TMyEnum read FMyEnum write FMyEnum;
published
property MyEnumOrd: Integer read GetMyEnumOrd write SetEnumOrd; //
gets/sets MyEnum as ordinal value
Ondrej
More information about the fpc-pascal
mailing list