Is it really SmallInt? Sometimes hovering variables at design-time gives wrong info because there can be some conditions, i.e. this:
I don't think it matters much.
According to Free Pascal Language Reference Guide Types>Base types>Ordinal types: "The integer type is an alias to the smallint type in the default Free Pascal mode. It is an alias for the longint type in either Delphi or ObjFPC mode."
So, the maximum value of an integer type is longint, which is smaller than the maximum value of a dword(longword). Notice that variable "phnum" is dword type. This means that iterations between high(integer) and high(dword) won't run.
The proposed code removes the variable "i" which will get rid of any error regarding the compatibility between integer and dword variable types.