I'm making a drive write-test button/script with custom (non-detached) dialog for settings UI (my USB 3.0 stick has write corruption when plugged to USB 3.0 which prompted this project).
However this code fails:
function OnClick(clickData)
{
var drives = DOpus.FSUtil.Drives();
var dlg = clickData.func.Dlg;
dlg.template = "drivetest";
dlg.Control("comboDrives"); // ???
var retVal = dlg.Show;
}
More specifically, attempt to use the dlg.Control fails with
Error at line 7, position 2
A method was called unexpectedly (0x8000ffff)
The button with embedded dialog resource XML is attached (but I think that the problem is in my code). Drive write test.dcf (2.5 KB)
Setting dlg.template does not create the dialog on its own, so the "comboDrives" control doesn't exist yet.
dlg.Show() will create the dialog and display it.
If you want to modify controls and set things up before displaying the dialog, add a call to dlg.Create() before the dlg.Control(...) call and anything similar, then call dlg.Show() to finally show it after everything is set up.
function OnClick(clickData)
{
var drives = DOpus.FSUtil.Drives();
var dlg = clickData.func.Dlg;
dlg.template = "drivetest";
dlg.Create();
var x = dlg.Control("comboDrives");
var retVal = dlg.Show();
}
Note that you need to use the Control object, or assign it to a variable (var x in my code here), else you'll get an error because it's returning an object which isn't stored. (Windows scripting is weird like that.)
You can use dlg.RunDlg() instead of dlg.Show() if you want to turn what you have into a non-detached dialog.
Thanks, that was the info I needed!
For future reference, I managed to make it work like this now:
dlg.Create(); // detach (so we can access controls)
// ...do things with controls...
dlg.Show(); // show detached
var retVal = dlg.RunDlg(); // reattach to prevent dialog from closing instantly