Browse Source

* Simplify GetEnumNameCount (by Lagprogramming). Fixes issue #40411

Michaël Van Canneyt 1 year ago
parent
commit
6a07a508b8
1 changed files with 3 additions and 11 deletions
  1. 3 11
      rtl/objpas/typinfo.pp

+ 3 - 11
rtl/objpas/typinfo.pp

@@ -1212,29 +1212,21 @@ begin
    end;
    end;
 end;
 end;
 
 
-
 function GetEnumNameCount(enum1: PTypeInfo): SizeInt;
 function GetEnumNameCount(enum1: PTypeInfo): SizeInt;
 var
 var
   PS: PShortString;
   PS: PShortString;
-  PT: PTypeData;
-  Count: SizeInt;
 begin
 begin
-  PT:=GetTypeData(enum1);
   if enum1^.Kind=tkBool then
   if enum1^.Kind=tkBool then
     Result:=2
     Result:=2
   else
   else
     begin
     begin
-      Count:=0;
-      Result:=0;
-
-      PS:=@PT^.NameList;
+      PS:=@GetTypeData(enum1)^.NameList;
+      Result:=-1;
       While (PByte(PS)^<>0) do
       While (PByte(PS)^<>0) do
         begin
         begin
           PS:=PShortString(pointer(PS)+PByte(PS)^+1);
           PS:=PShortString(pointer(PS)+PByte(PS)^+1);
-          Inc(Count);
+          Inc(Result);
         end;
         end;
-      { the last string is the unit name }
-      Result := Count - 1;
     end;
     end;
 end;
 end;