HTMLelement.onClick event seems to require constants rather than vars in function parms & thus, not allowing 1 code line in a Loop. Is there a work around?
I’m trying to create multiple elements, Labels in example, in a loop with an Array of the elements as follows:
LabRC : Array[0..nRows, 0..nCols] of dynamic; //A global array used by many methods.
xRow = 0; //NOTE: xRow is a global constant for example
method createLabels;
begin
var iCol : Integer;
var sID : String;
for iCol := 0 to nCols do begin
sID := ‘RC0’ + iCol.ToString;
LabRC[xRow, iCol] := WebAssembly.CreateElement('label');
LabRC[xRow, iCol].ID := sID;
LabRC[xRow, iCol].innerHTML := sLabTxt[xRow, iCol]; //The Label text in an array
LabRC[xRow, iCol].style := // a Style string w/ int Var's ToString + text all works fine
//But cannot set onclick event with vars. Oxygene seems to require constants
//LabRC[xRow, 0].onclick := new WebAssemblyDelegate( (a) -> selClick(xRow, iCol)); *** FAILS ***
//The following works, but requires unique code line for each Label's onClick event.
case iCol of //This works, but can't make 0, 1, 2 a var to do in one line of code?
0: LabRC[xRow, 0].onclick := new WebAssemblyDelegate( (a) -> selClick(xRow, 0));
1: LabRC[xRow, 1].onclick := new WebAssemblyDelegate( (a) -> selClick(xRow, 1));
2: LabRC[xRow, 2].onclick := new WebAssemblyDelegate( (a) -> selClick(xRow, 2));
end;//EndCASE iCol
el.appendChild(LabRC[xRow, iCol]);
end; //EndFOR iCol
end; //EndMethod createLabels