Generics. Does not compile.
Original Reporter info from Mantis: VaalKIA
-
Reporter name:
Original Reporter info from Mantis: VaalKIA
- Reporter name:
Description:
In all versions of the compiler.
I am attaching the lazarus project (line 71 (lst:=lst^.next;)).
type
LstGrandTyp = ^LstGrandForwardTyp;
LstGrandForwardTyp = packed record
early, Next: LstGrandTyp;
end;
LstTyp01 = ^LstForwardTyp01;
LstForwardTyp01 = packed record
early, Next: LstTyp01;
Value: byte;
end;
LstTyp02 = ^LstForwardTyp02;
LstForwardTyp02 = packed record
early, Next: LstTyp02;
Value: string[255];
end;
implementation
type
generic LstEnumerator<T> = record
private
lst, lst_save: T;
public
constructor Create(const Value: T);
function GetEnumerator: LstEnumerator;
function MoveNext: boolean;
property Current: T read lst;
end;
constructor LstEnumerator.Create(const Value: T);
begin
lst := Value;
lst_save := nil;
end;
function LstEnumerator.GetEnumerator: LstEnumerator;
begin
Result := Self;
end;
function LstEnumerator.MoveNext: boolean;
begin
if lst <> nil then
begin
//LstGrandTyp(lst) := LstGrandTyp(lst)^.next;//particular case. Compilled
lst:=lst^.next;
//T(lst) := T(lst)^.next;//T is specialize of LstTyp01 of LstTyp02 or LstGrandTyp
Result := True;
end else Result := False;
end;
{$R *.lfm}
var
i01, lst01: LstTyp01;
i02, lst02: LstTyp02;
i03, lst03: LstGrandTyp;
en01: specialize LstEnumerator<LstTyp01>;
en02: specialize LstEnumerator<LstTyp02>;
en03: specialize LstEnumerator<LstGrandTyp>;
begin
for i01 in en01.Create(lst01) do
begin
i01^.Value := 10;
end;
for i02 in en02.Create(lst02) do
begin
i02^.Value := 'ten';
end;
for i03 in en03.Create(lst03) do
begin
end;
end.
Mantis conversion info:
- Mantis ID: 33700
- OS: Windows 7 x64
- OS Build: sp1
- Build: 57729
- Platform: x86_64
- Version: 3.1.1