- edited description
Anonymous record
There is error when using Anonymous record (Using the Codegen)
var v : Variant;
...
v := record
'name'= 'hello';
'size'= 3;
'width' = 5;
end;
It outputs as a JSON text: {'name$4': ‘hello’, ‘size’: 3, ‘widht$5’: 5}
Name, Width, Height properties are wrong.
And with recursive object, the result is wrong too:
v := record
'name'= 'hello';
'size'= 3;
'extension' = record
'name'= 'hello';
'size'= 3;
'width' = 5;
end;
end;
end;
It outputs in JS many codes that I think useless.
Comments (13)
-
reporter -
repo owner For that usage you should be using an anonymous class, which is tagged as external by default.
Record also have a lot of overhead in the codegen to emulate Delphi behavior, as they are value types, which do not really exist in JS (which only knows mutable classes)Just use “class” where you used “record”.
var v := class 'name'= 'hello'; 'size'= 3; 'width' = 5; end;
-
repo owner - changed status to resolved
-
reporter Hello Eric,
I tested it and an Access violation error occured when using it.
Regards,
-
reporter But If I remove AlloClosures option for the compiler, there is a Syntax Error. But there is no Access violation error.
Thank you,
Regards.
-
reporter - marked as minor
-
repo owner Could you copy-paste the whole source code that triggers the issue ?
-
reporter Sure:
program Test; begin var y: variant; var t:= record name = 8; height = 10; size: record name = 'tool'; end; end; var x := class //If I use record, No Access violation Error name = "rakoto"; size = class //If I use record, No Access violation Error height = 3; width = 2; end; end; // y := t; //Error assigning anonymous record to variant end.
-
reporter The error occurs when Codegen’ed it not when compiling.
Thank you so much for your support.
-
repo owner Hmm, I cannot reproduce it, are you using the git version ?
-
reporter I downloaded the version from the bitbucket repository. I got the error when generating JS code (using the LiveScripting demos).
Code Used:
procedure TFrmBasic.AcnCodeGenJSExecute(Sender: TObject); begin {$IFDEF JS} FJSCOdeGen.Clear; FJSCodeGen.CompileProgram(FCompiledProgram); SaveTextToUTF8File('dws.js', FJSCodeGen.CompiledOutput(FCompiledProgram)); {$ENDIF} end;
-
reporter I downloaded the version from the bitbucket repository. I got the error when generating JS code (using the LiveScripting demos). Code Used:
procedure TFrmBasic.AcnCodeGenJSExecute(Sender: TObject);begin {$IFDEF JS} FJSCOdeGen.Clear; FJSCodeGen.CompileProgram(FCompiledProgram); SaveTextToUTF8File('dws.js', FJSCodeGen.CompiledOutput(FCompiledProgram)); {$ENDIF}end;
-
repo owner - Log in to comment