[fpc-devel] ConvUtils: ConvTypeToFamily and ConvFamilyToDescription conundrums

Bart bartjunk64 at gmail.com
Wed Jun 8 15:14:26 CEST 2022

On Wed, Jun 8, 2022 at 11:43 AM Bart <bartjunk64 at gmail.com> wrote:

> And another observation: on Delphi 7 TConvType seems to be unsiged (in
> fpc it's signed).

Actually it is documented to be of type Word:
I guess nobody needs more than 65536 conversion types, so most likely
not a problem.

So, this is not an implementation detail (which we could simply
ignore), but actually it is now a bug.

Changing our TConvType to word will potentially break existing programs though.
Consider the following code:
  Fam: TConvFamily;
  Fams: TConvFamilyArray;
  Len: Integer;
  Len := Length(Fams);
  if (Len=0) then
    writeln('Nothing registered yet');
  for Fam := Low(Fams) to High(Fams) do
    writeln(format('%d: "%s"',[ord(fam),ConvFamilyToDescription(fam)]));

If Len=0 this then High(Fams) will be Word(-1) and the loop will print
65536 non-existing families.
(Which is why you should always use signed integers in a for loop)

All this leads me to the conclusion that they (the Greek) did not
really desing this unit very well.


More information about the fpc-devel mailing list