Help with OnActivateTab

I will attach a test script which displays a demo dialog. I added an OnActivateTab function but it doesn't fire when I change tabs whilst the dialog is being displayed.

function OnInit(initData)
{
	initData.name = "qnddlg";
	initData.vars("name") = initData.name;
	initData.desc = "Quick and Dirty dialog testbed";
	initData.copyright = "(c) 2018 Aussie";
	initData.version = "1.0";
	initData.vars("version") = initData.version;
	initData.default_enable = true;
	
	var cmd = initData.AddCommand();
	cmd.name = initData.name;
	cmd.method = "do_main";
	cmd.desc = initData.desc;
	cmd.label = initData.name;
	cmd.template = "parms/m";
	
	initData.config_desc = DOpus.create.map();
	initData.config.dbg = true;
	initData.config_desc("dbg") = 'Set to TRUE to write trace information to "Other" log.';
}

//-- Global Variables

var d, f, c, fsu;
var src, tgt, dlg;
var msg, btns, title;
var item, str;
var dbg;

function do_main(clickData)
{
	dbg = Script.config.dbg;
	if (dbg) DOpus.output(Script.vars("name")+" version "+Script.vars("version")+" starting..");
	d = clickData;
	f = d.func;
	c = f.command;
	fsu = DOpus.FSUtil;
	src = f.sourcetab;
	dlg = src.dlg
	tgt = f.desttab;
	//-- Start test code here...
	dlg.window = src;
	dlg.template = "demo";
	dlg.detach = true;
	dlg.create;
	var iteration = 0;
	var msg_obj, ctl_name;
	dlg.show;
	do{
		msg_obj = dlg.getmsg();
		if (msg_obj==false) break; // User clicked X
		ctl_name = msg_obj.control;
		if (dbg){
			str = iteration++;
			str+= " : msg_obj.event = " + msg_obj.event;
			str+= " : msg_obj.control = " + ctl_name;
			DOpus.output(str);
		}
	}
	while (msg_obj);
}

function OnActivateTab(ActivateTabData)
{
	if (dbg) DOpus.output("ActivateTabData.oldtab = " + ActivateTabData.oldtab);
	if (dbg) DOpus.output("ActivateTabData.newtab = " + ActivateTabData.newtab);
}

==SCRIPT RESOURCES
<resources>
	<resource name="demo" type="dialog">
		<dialog fontsize="8" height="87" lang="english" standard_buttons="cancel" width="108">
			<control height="57" name="group1" title="Demo Radio" type="group" width="77" x="14" y="6" />
			<control checked="yes" group="yes" height="10" name="radio1" title="Radio Button 1" type="radio" width="64" x="19" y="22" />
			<control height="10" name="radio2" title="Radio Button 2" type="radio" width="64" x="19" y="34" />
			<control height="10" name="radio3" title="Radio Button 3" type="radio" width="64" x="19" y="46" />
		</dialog>
	</resource>
</resources>

Unfortunately, Windows Scripting Host doesn't support re-entrancy; if your script is already running (sitting in the dialog loop) it can't be invoked a second time to run the callback function.

The only way would be for Opus to make a copy of the script in memory, but the two copies would be completely separate and unable to share data which is probably not what you'd want.

In the future we might be able to look at diverting the callback functions into dialog mesages so that, for example, if you're in a dialog loop you'd get a message of type "activatetab" - but in the short term I don't think there's an easy solution.

Ignore everything I just said :slight_smile:

I tried your script and it actually does seem to call the OnActivateTab method when the dialog is open. The problem is the if (dbg) test in the function is failing, so nothing gets printed to the log. If you take that out then you should see that the callback is called even with the dialog running.

Well this is creepy stuff. As you can see from the earlier if (dbg) statements which do generate output there is no obvious reason why nothing is output from the OnActivateTab function. I played around and discovered that output is only suppressed if both of the DOpus.output statements are prefixed with if (dbg) but not if only one or neither is prefixed. I can't see anything to explain why that should be. The statements both look fine to me.

It seems that whilst dbg is declared globally and initialised on entry to do_main, it is seen as undefined on entry to the OnActivateTab function. No doubt something to do with the way event functions are handled.

Try using an Opus Var to store the global state.