Forum > Pas2JS
Modifying TJSArray object members
(1/1)
rlsdevine:
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:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- TUser = record FirstName: string; Surname: string; DisplayName: string; end;
My TJSArray is a private field variable of the class:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- private FUserList: TJSArray;
I'm testing different ways of modifying members of the array:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- // -- 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
Navigation
[0] Message Index