[SOLVED] Simplified GetEnumNameCount lazarus / 64-FPC development ---------------------------------------------------------------------- lagprogramming · 2023-08-23 13:35 rtl/objpas/typinfo.pp has Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function GetEnumNameCount(enum1: PTypeInfo): SizeInt;var  PS: PShortString;  PT: PTypeData;  Count: SizeInt;begin  PT:=GetTypeData(enum1);  if enum1^.Kind=tkBool then    Result:=2  else    begin      Count:=0;    Result:=0;       PS:=@PT^.NameList;      While (PByte(PS)^<>0) do      begin          PS:=PShortString(pointer(PS)+PByte(PS)^+1);        Inc(Count);        end;      { the last string is the unit name }    Result := Count - 1;    end;end; The above function has been simplified. Variable "Count" has been replaced by "Result"; Removed the last "Result := Result - 1;" line by replacing "Result:=0;" with "Result:=-1;" Switched "Result:=-1;" and "PS:=@PT^.NameList;" lines; Variable "PT" has been removed by replacing "PS:=@PT^.NameList;" with "PS:=@GetTypeData(enum1)^.NameList;". The function becomes: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function GetEnumNameCount(enum1: PTypeInfo): SizeInt;var  PS: PShortString;begin  if enum1^.Kind=tkBool then    Result:=2  else    begin      PS:=@GetTypeData(enum1)^.NameList;      Result:=-1;      While (PByte(PS)^<>0) do        begin          PS:=PShortString(pointer(PS)+PByte(PS)^+1);          Inc(Result);      end;    end;end; The patch is attached to the message. ---------------------------------------------------------------------- AlexTP · 2023-08-24 06:07 Posted to https://gitlab.com/freepascal.org/fpc/source/-/issues/40411