Advanced record constructors generate JavaScript code that is valid for classes, but not advanced records.
Original Reporter info from Mantis: Akira1364
-
Reporter name:
Original Reporter info from Mantis: Akira1364
- Reporter name:
Description:
The following program:
program JSTest;
{$modeswitch AdvancedRecords}
uses NodeJS;
type
TTestRec = record
private
FString: String;
public
constructor Create(const AString: String);
property StringVal: String read FString;
end;
constructor TTestRec.Create(const AString: String);
begin
FString := AString;
end;
var T: TTestRec;
begin
T := TTestRec.Create('hello');
Console.Log(T.StringVal);
end.
produces this output:
rtl.module("program",["System","NodeJS"],function () {
"use strict";
var $mod = this;
rtl.recNewT($mod,"TTestRec",function () {
this.FString = "";
this.$eq = function (b) {
return this.FString === b.FString;
};
this.$assign = function (s) {
this.FString = s.FString;
return this;
};
this.Create = function (AString) {
this.FString = AString;
return this;
};
},true);
this.T = $mod.TTestRec.$new();
$mod.$main = function () {
$mod.T.$assign($mod.TTestRec.$create("Create",["hello"]));
console.log($mod.T.FString);
};
});
$create does not exist for records, so running the program results in:
"TypeError: mod.TTestRec.
create is not a function"
Steps to reproduce:
Build and run the example program above.
Mantis conversion info:
- Mantis ID: 35353
- OS: Windows
- OS Build: 10
- Build: 1.5.1
- Platform: x86_64
- Fixed in revision: 41856.