Simple Dialog Test, DO freezes

Hi there!

Is it me or is it DO doing something unexpected here?
This dialog-test will make DO hang/freeze when pressing the "Close" button.
I'm on the latest 12.5.1 beta.

Thanks! o)

<?xml version="1.0"?>
<button backcol="none" display="label" textcol="none">
	<label>ISEFilter</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>function OnClick(data) {</instruction>
		<instruction>	var Dlg = DOpus.Dlg;</instruction>
		<instruction>	Dlg.window = data.func.sourcetab;</instruction>
		<instruction>	Dlg.template = &quot;ISEFilter_dlg&quot;;</instruction>
		<instruction>	Dlg.detach = true;</instruction>
		<instruction>	Dlg.Show(); </instruction>
		<instruction>    do {</instruction>
		<instruction>		var Msg = Dlg.GetMsg();</instruction>
		<instruction>		DOpus.Output(&quot;Msg:&quot; + Msg.event);</instruction>
		<instruction>	} while (Msg);</instruction>
		<instruction>    DOpus.Output(&quot;Return code = &quot; + Dlg.result);</instruction>
		<instruction>}</instruction>
		<instruction>==SCRIPT RESOURCES</instruction>
		<instruction>&lt;resources&gt;</instruction>
		<instruction>	&lt;resource name=&quot;ISEFilter_dlg&quot; type=&quot;dialog&quot;&gt;</instruction>
		<instruction>		&lt;dialog fontsize=&quot;8&quot; height=&quot;142&quot; lang=&quot;&quot; width=&quot;352&quot;&gt;</instruction>
		<instruction>			&lt;control halign=&quot;left&quot; height=&quot;12&quot; name=&quot;Filter_tbx&quot; title=&quot;Edit Control&quot; type=&quot;edit&quot; width=&quot;292&quot; x=&quot;28&quot; y=&quot;24&quot; /&gt;</instruction>
		<instruction>			&lt;control close=&quot;0&quot; height=&quot;14&quot; name=&quot;button1&quot; title=&quot;Close&quot; type=&quot;button&quot; width=&quot;50&quot; x=&quot;282&quot; y=&quot;108&quot; /&gt;</instruction>
		<instruction>		&lt;/dialog&gt;</instruction>
		<instruction>	&lt;/resource&gt;</instruction>
		<instruction>&lt;/resources&gt;</instruction>
	</function>
</button>

I was having a similar problem, it wasn't freezing but causing the CPU usage to climb after each script run and found this to be the solution for my problem. I tested with your example and it also works...

change
while (Msg);
to
while (Msg == true);

It looks like the sample code for VBScript doesn't translate directly into JScript.

The Msg docs show you can do things another way, using Msg.result to check if the message is valid. (You can also check if Msg.event is the string "invalid".)

Try this:

function OnClick(data) {
	var Dlg = DOpus.Dlg;
	Dlg.window = data.func.sourcetab;
	Dlg.template = "ISEFilter_dlg";
	Dlg.detach = true;
	Dlg.Show(); 
    while (true) {
		var Msg = Dlg.GetMsg();
		if (!Msg.result) break;
		DOpus.Output("Msg:" + Msg.event);
	}
    DOpus.Output("Return code = " + Dlg.result);
}

(That also avoids doing anything with the message when it is invalid, as it breaks out of the loop earlier.)

Yonder's suggestion also seems to work, although I am not really sure why that works and the original way does not. It may be a quirk of JScript and how/when it decides to turn objects into booleans.

I think using Msg.result is best as it's the most explicit, and it works whether you test it for being true or false.

Ok, works now. Thank you both! o)

I had a look at this and the evaluation of Msg in the loop (while (Msg)) doesn't actually result in any calls into our object at all. So I think JScript is evaluating the variable as to whether it's "empty" or not, rather than treating it like an object and calling its default dispatch method as VBScript does.