I'm actually using pas2js from TMS WebCore (Delphi) but this question seems to be a pas2js thing. I have a TJSArray (retrieved via JSON from an API call) that holds a number of objects that define users, e.g. in Object Pascal:
TUser = record
FirstName: string;
Surname: string;
DisplayName: string;
end;
My TJSArray is a private field variable of the class:
private
FUserList: TJSArray;
I'm testing different ways of modifying members of the array:
// -- The following works correctly.
asm
this.FUserList[0].DisplayName = "Bob1";
end;
console.log('DisplayName: ' + TUser(FUserList[0]).DisplayName);
// -- The following line fails to compile: "Variable identifier expected".
//TUser(FUserList[0]).DisplayName := 'Bob2';
//console.log('DisplayName: ' + TUser(FUserList[0]).DisplayName);
// -- The following works correctly.
TJSObject(FUserList[0]).Properties['DisplayName'] := 'Bob3';
console.log('DisplayName: ' + TUser(FUserList[0]).DisplayName);
The puzzle is that I can hard cast TUser(FUserList[0]) to get the DisplayName for the console output, but can't get it to compile when setting the value. Obviously not a show-stopper but curious how to get around this. I also tried (FUserList[0] as TUser) but that won't compile either.
Thanks, Bob