<div dir="ltr"><div dir="ltr"></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Aug 11, 2022 at 9:37 PM Martin Frb via fpc-devel <<a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div>fpc code is still "unexpected".<br></div>
It takes into account the MinValue<br>
<br>
type TMyEnum = (a=5, b=7);<br>
<br>
GetEnumName(pt, 5) // a<br>
GetEnumName(pt, 6) // b // should be 7<br>
<br>
if it is just the nth name, then it should start at 0 (or if needs
be at 1).</div></blockquote><div><br></div><div>And function GetEnumValue() is buggy.</div><div>This was noticed when testing the original Lazarus enum property editor bug.<br></div><div>A little modified enum :</div><div><br></div><div>type</div><div> TFruitMore = (fmApple=1, fmOrange=3, fmBanana=5, fmGrapes, fmPear);<br></div><div></div>var<br> I: Integer;<br> EnumType: PTypeInfo;<br><div>...</div><div> I := GetEnumValue(EnumType, 'fmBanana'); // Returns 3</div><div></div><div> I := GetEnumValue(EnumType, 'fmGrapes'); // Returns 4 which is an illegal value</div><div><br></div><div>Looking at the source of GetEnumValue() the reason is clear.</div><div>It increments Count one by one while it should take the gaps into account.</div><div></div><div>---</div><div> PS:=@PT^.NameList;<br> While (Result=-1) and (PByte(PS)^<>0) do<br> begin<br> If ShortCompareText(PS^, sName) = 0 then<br> Result:=Count+PT^.MinValue;<br> PS:=PShortString(pointer(PS)+PByte(PS)^+1);<br> Inc(Count);<br> end;<br></div><div>---</div><div>Where are the ordinal values for enums stored? They are not in TTypeData.</div><div>I wanted to fix this right away but I have no idea how.</div><div><br></div><div>Regards,</div><div>Juha</div><div><br></div></div></div>