Hi, I try to adopt outstanding and free Pas2js transpiler to Delphi language. My main development IDE is Delphi CE Rio, so I decided to try a new Delphi syntax: generic collections and inline variables. And stumbled upon a runtime error. The code (simplified):
program TestInlineVarForDictionary;
{$APPTYPE CONSOLE}
{$R *.res}
uses SysUtils, Generics.Collections;
procedure TestDictErr;
var
Dict: TDictionary<string,TObject>;
begin
Dict := TDictionary<string,TObject>.Create;
for var item in Dict do
Writeln('Key = ', item.Key, 'Name = ', item.Value.ClassName);
end;
procedure TestDictOK;
var
Dict: TDictionary<string,TObject>;
item: TPair<string,TObject>;
begin
Dict := TDictionary<string,TObject>.Create;
for item in Dict do
Writeln('Key = ', item.Key, 'Name = ', item.Value.ClassName);
end;
begin
try
//!!TestDictOK;
TestDictErr;
except
on E: Exception do begin
Writeln(E.ClassName, ': ', E.Message);
Write('Press Enter to continue...');
Readln;
end;
end;
end.
This program causes Exception class $C0000005 with message 'access violation at 0x0040a86e: write of address 0x0040a29e'. Can you confirm it? Is it a bug in the compiler or/and RTL, or am I misusing the new syntax?
It's interesting: if you uncomment TestDictOK that does enumeration in old-style, the exception will disappear!