Hi,
I was wanting to display a message box that give's the user 4 choices. The standard DzMessageBox has methods that allow up to 3 buttons/choices for the user, so I thought I would design a custom dialog that allows a variable number of buttons to be displayed. The snippet shows how I've gone about this, and in particular how I've connected each button's signal with a function that tells me which button has been pressed. The code seems to work OK, but I'm no javascript guru. I can't help wondering if there's a better way of coding this instead of using 'eval()':
var oDlg = new DzDialog();
oDlg.caption = "My Dialog Box";
var nBtnPressed;
var oVBoxLayout = new DzVBoxLayout(oDlg);
oVBoxLayout.autoAdd = true;
for (var i = 0; i < 4; i++) {
var oBtn = new DzPushButton(oDlg);
oBtn.autoDefault = false;
oBtn.text = "Button: " + i;
var code
= "function fnc() {"
+ " nBtnPressed = " + i + ";"
+ " oDlg.close();"
+ "}";
eval(code);
connect(oBtn, "clicked()", fnc );
}
oDlg.exec();
print(nBtnPressed);