I'm trying to generate buttons within a loop (one button for each column). The buttons are created correctly except that when the button executes its script it will always execute the script of the lastly created button - instead of the script that was passed to the button box object when it was created.
So, it seems that the button gets only a reference to the script - and if script is changed the button will change its function. I tried considering workaround with array of scripts but the problem is that I can't pass any argument for the button object (e.g. index which script in the array to execute).
Question: Is there any way in jsl that one can create buttons within a loop with different scripts/behaviour? E.g. is there any way of passing arguments/data to button object when it is created???
My code:
NamesDefaultToHere(1);
dt = Current Data Table();
dtCols = dt << Get Column Names( Numeric, Continuous );
// Expression for displaying distribution for strParam
Expr_ShowDistribution = Expr(
New Window( Char(strParam),
Distribution(
Continuous Distribution(
Column( strParam ) //We specify our parameter
),
SendToReport(
Dispatch( {}, "Distribution", OutlineBox, Set Title( "" ) ),
)
)
)
);
// Main Window
New Window("Main Window",
ob = OutlineBox("Buttons",
TextBox("Debugging buttons", Set Font Style("Bold"))
);
);
// Create button that only outputs to log
BB = Button Box( "ClickMe", Show("Clicked"));
ob << Append(BB);
// Create buttons for showing distributions
For( i = 1, i <= NItems(dtCols), i++,
Expr_ButtonAction = Substitute(NameExpr(Expr_ShowDistribution),
Expr(strParam), Eval(Char(dtCols)) );
Show(NameExpr(Expr_ButtonAction)); // Expression is different for each button.
BB = Button Box( Char(dtCols), Eval(Expr_ButtonAction));
ob << Append(BB);
);