Cannot use generic variable for in "for" loop
Original Reporter info from Mantis: petkos
-
Reporter name:
Original Reporter info from Mantis: petkos
- Reporter name:
Description:
this line cannot be compiled
for I:= C(Startindex) to C(EndIndex) do Index[I]:= I;
then error message is:
project1.lpr(37,9) Error: Ordinal expression expected
Additional information:
program project1;
{$MODE OBJFPC}{$H+}{$B-}
uses
SysUtils;
type generic
TDynArray<T> = array of T;
type generic
TSorter<T, C> = class
protected
var
Tmp: C;
procedure _Sort(constref Index: specialize TDynArray<C>;
constref Values: specialize TDynArray<T>;
StartIndex, EndIndex: Int32); virtual;
public
procedure Sort(constref Index: specialize TDynArray<C>;
constref Values: specialize TDynArray<T>;
StartIndex, EndIndex: Int32); virtual;
end;
procedure TSorter.Sort(constref Index: specialize TDynArray<C>;
constref Values: specialize TDynArray<T>;
StartIndex, EndIndex: Int32);
var
Len: Int32;
I : C;
begin
// some code
Len:= System.Length(Values);
if (Len = 0) or ( Assigned(Index) and (Len <> System.Length(Index)) ) then Exit;
if Assigned(Index)
then begin
for I:= C(Startindex) to C(EndIndex) do Index[I]:= I;
I:= 1;
end;
Self._Sort(Index, Values, StartIndex, EndIndex);
end;
procedure TSorter._Sort(constref Index: specialize TDynArray<C>;
constref Values: specialize TDynArray<T>;
StartIndex, EndIndex: Int32);
begin
// some code
end;
var
s: specialize TSorter<Unicodestring, Int32>;
begin
s:= specialize TSorter<Unicodestring, Int32>.Create;
end.
Mantis conversion info:
- Mantis ID: 32111
- OS: Windows
- Platform: x64, x86
- Version: 3.1.1
- Fixed in revision: 36722 (#ca78bfff)