<div dir="ltr"><div>I was able to fix issue</div> <a href="https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39832">https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39832</a><br><div>about TEnumPropertyEditor in Lazarus IdeIntf.</div><div>Explanation:</div><div></div><div>function GetEnumName() in FPC's rtl/objpas/typinfo.pp returns the enum's unit name for one gap in a non-contiguous enum, and an empty string for the other gaps. IMO returning the unit name can be considered a bug in FPC code.<br>Fortunately TPropertyEditor has a method GetPropTypeUnitName(), made by Mattias I guess, which I could use to filter out the unit name. An enum element cannot have the same name as the unit which makes this a robust solution.<br></div><div>This is the fixed property editor method:</div><div><br></div><div>procedure TEnumPropertyEditor.GetValues(Proc: TGetStrProc);<br>var<br>  I: Integer;<br>  EnumType: PTypeInfo;<br>  s, EnumUnitName: String;<br>begin<br>  EnumType := GetPropType;<br>  EnumUnitName := GetPropTypeUnitName;<br>  with GetTypeData(EnumType)^ do<br>    for I := MinValue to MaxValue do begin<br>      s := GetEnumName(EnumType, I);<br>      // An empty string and the enum's unit name happen in gaps<br>      // of a non-contiguous enum. Why the unit name? A bug in FPC code?<br>      if (s <> '') and (s <> EnumUnitName) then<br>        Proc(s);<br>    end;<br>end;<br></div><div><br></div><div>Property editors deal with RTTI.</div><div>I started to think about how such enum elements are iterated in a normal user code which doesn't need RTTI.</div><div>I came up with this, using the Fruit example enum from the bug report:</div><div><br></div><div>program enumconsole;<br>type<br>  //TFruit = (fApple, fOrange, fBanana, fGrapes, fPear);<br>  TFruitMore = (fmApple=0, fmOrange=2, fmBanana=4, fmGrapes, fmPear);<br>const<br>  CFruitMoreSet = [fmApple, fmOrange, fmBanana, fmGrapes, fmPear];<br>var<br>  e: TFruitMore;<br>begin<br>  for e := Low(TFruitMore) to High(TFruitMore) do<br>    if e in CFruitMoreSet then<br>      WriteLn(Ord(e), ': ', e);<br>end.<br></div><div><br></div><div>It seems there is no easy way, or at least I didn't find any.</div><div>The code requires a constant set with all enum elements included. Feels like a hack.</div><div>Leaving out the test "if e in CFruitMoreSet then" leads to a run time error.</div><div>If there is a better way to iterate, please tell me.</div><div><br></div><div>Regards,</div><div>Juha</div><div><br></div></div>