Anonymous record

Issue #182 resolved
Toky Olivier Razanakotonarivo created an issue

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)

  1. Eric Grange 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;
    
  2. Toky Olivier Razanakotonarivo reporter

    Hello Eric,

    I tested it and an Access violation error occured when using it.

    Regards,

  3. Toky Olivier Razanakotonarivo 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.

  4. Toky Olivier Razanakotonarivo 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. 
    

  5. Toky Olivier Razanakotonarivo reporter

    The error occurs when Codegen’ed it not when compiling.

    Thank you so much for your support.

  6. Toky Olivier Razanakotonarivo 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;
    

  7. Toky Olivier Razanakotonarivo 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;

  8. Log in to comment