Hi, I am trying to write some generic routines for working with containers. For example, GetLength function:
unit u; {$MODE FPC} {$MODESWITCH DEFAULTPARAMETERS} {$MODESWITCH OUT} {$MODESWITCH RESULT} interface generic function GetLength<TContainter>(const V: TContainter): SizeUInt; implementation generic function GetLength<TContainter>(const V: TContainter): SizeUInt; begin Exit(V.Count); end; end. // the program {$MODE FPC} {$MODESWITCH DEFAULTPARAMETERS} {$MODESWITCH OUT} {$MODESWITCH RESULT} {$MODESWITCH TYPEHELPERS} uses u; type TDynArray = array of PtrInt; TDynArrayHelper = type helper for TDynArray function Count: SizeUInt; end; function TDynArrayHelper.Count: SizeUInt; begin Exit(System.Length(Self)); end; var V: TDynArray; begin v := [0, 1, 2, 3, 5, 6, 7, 10, 11, 12, 13, 15, 16]; Writeln(specialize GetLength<TDynArray>(v)); end. It gives the following compilation error: u.pas(16,10) Error: Illegal qualifier Is the problem because the helper is not known while compiling the unit? How do I write a generic routine GetLength which will work both for dynamic arrays and for records, objects, classes with Count property? -- Victor Matuzenko (Виктор Матузенко)
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal