Array of Record Type Add Create



Array of Record Type Add Create
Pas2JS pascal source code
type TRec = record name: string; id: integer; //why doesn't constructor syntax work here?!? class function Create(id: integer; name: string): TRec; end; class function TRec.Create(id: integer; name: string): TRec; begin result.id := id; result.name := name; end; procedure Testing; var recs: array of TRec; r : Trec; begin recs.add(TRec.Create(1, 'A')); r:=TRec.Create(2, 'b'); recs.Add(r); writeln(recs[0].id); writeln(recs[0].name); writeln(format('%s', [recs[0].name])); writeln(recs[1].id); writeln(recs[1].name); writeln(format('%s', [recs[1].name])); end; { unit1.pas } begin testing; { CONSOLE OUTPUT 1AA 2bb }