Hi, I've been trying to improve the ConvUtils unit. Now I've ran into a problem.
ConvTypeToFamily returns CIllegalConvFamily (=0) if AType is not registered. This however is a problem. If AType is a type registered in the first registered family, ConvTypeToFamily will also return 0. This means that the result value of ConvTypeToFamily cannot be used to determine wether or not AType actually is registered. This is IMHO not good. Related to this is the fact that in Delphi ConvFamilyToDescription(0) will return the strng "Illegal family" always, wether or not any families have been registered. (Tested with Delphi 7) ========= code begin ========== program dconv; {$apptype console} {$ifdef fpc} {$mode objfpc}{$h+} {$endif} uses sysutils,convutils; procedure ListFamilies; var Fam, FirstFam, SecFam: TConvFamily; Fams: TConvFamilyArray; tuFirstType, tuSecType: TConvType; Len, ExpLen: Integer; begin GetConvFamilies(Fams); Len := Length(Fams); if (Len=0) then writeln('Nothing registered yet'); writeln('Length(Fams)=',Len); if Len>0 then begin for Fam := Low(Fams) to High(Fams) do writeln(format('%d: "%s"',[ord(fam),ConvFamilyToDescription(fam)])); end else begin writeln('Testing with out of bound values'); writeln('ConvFamilyToDescription(0)="',ConvFamilyToDescription(0),'"'); writeln('ConvFamilyToDescription(1)="',ConvFamilyToDescription(1),'"'); end; writeln; writeln('Registering First and Second Family'); FirstFam := RegisterConversionFamily('First Family'); tuFirstType := RegisterConversionType(FirstFam, 'FirstType', 123.0); SecFam := RegisterConversionFamily('Second Family'); tuSecType := RegisterConversionType(SecFam, 'SecondType', 321.0); GetConvFamilies(Fams); ExpLen := Len+2; Len := Length(Fams); write('Length(Fams)=',Len); if (Len<>ExpLen) then writeln(' FAIL: Expected ',ExpLen) else writeln; if Len>0 then begin for Fam := Low(Fams) to High(Fams) do writeln(format('%d: "%s"',[ord(fam),ConvFamilyToDescription(fam)])); end; writeln('ConvFamilyToDescription(0)="',ConvFamilyToDescription(0),'"'); end; begin {$ifdef fpc} writeln('FPC'); {$else} writeln('Delphi'); {$endif} ListFamilies; end. ============ code end ========== Output in FPC: FPC Nothing registered yet Length(Fams)=0 Testing with out of bound values ConvFamilyToDescription(0)="" ConvFamilyToDescription(1)="" Registering First and Second Family Length(Fams)=2 0: "First Family" 1: "Second Family" ConvFamilyToDescription(0)="First Family" Output in Delphi: Delphi Nothing registered yet Length(Fams)=0 Testing with out of bound values ConvFamilyToDescription(0)="Illegal family" ConvFamilyToDescription(1)="[$00000001]" Registering First and Second Family Length(Fams)=2 0: "Illegal family" 1: "First Family" ConvFamilyToDescription(0)="Illegal family" The output of Delphi (7) is obviously totally wrong. Before I can even start to try to fix this I really need to know how current Delphi actually behaves. As long as we want to have ConvTypeToFamily and CIllegalConvFamily compatible with Delphi, the function RegisterConversionFamily() should never return CIllegalConvFamily . I.o.w. the internal array should not start at 0 (or the 0-index should be filled with info that represents an illegal family). So, any fix would break Delphi compatibility? Q1: Can somebody test with a modern Delphi? Q2: Any comments on the pargraph above? -- Bart _______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel