I don't think you can reliably re-use the exact same dlg object, but you can create a second dlg object for the same dialog without any issues.
Example using a detached dialog:
function OnClick(clickData)
{
for (var showCount = 0; showCount < 2; ++showCount)
{
var Dlg = DOpus.Dlg;
Dlg.window = clickData.func.sourcetab;
Dlg.template = "dialog1";
Dlg.detach = true;
Dlg.Create();
var listview = Dlg.Control("listview1");
var i = listview.AddItem("Line 1");
listview.GetItemAt(i).subitems(0) = "L1.0";
listview.GetItemAt(i).subitems(1) = "L1.1";
i = listview.AddItem("Line 2");
listview.GetItemAt(i).subitems(0) = "L2.0";
listview.GetItemAt(i).subitems(1) = "L2.1";
Dlg.Show();
while (true)
{
var Msg = Dlg.GetMsg();
if (!Msg.result) break;
DOpus.Output("Msg Event = " + Msg.event);
if (Msg.event == "click" && Msg.control == "Autosize")
{
listview.columns.AutoSize();
}
}
DOpus.Output("Return code = " + Dlg.result);
}
}
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>New Button</label>
<icon1>#newcommand</icon1>
<function type="script">
<instruction>@script JScript</instruction>
<instruction>function OnClick(clickData)</instruction>
<instruction>{</instruction>
<instruction> for (var showCount = 0; showCount < 2; ++showCount)</instruction>
<instruction> {</instruction>
<instruction> var Dlg = DOpus.Dlg;</instruction>
<instruction> Dlg.window = clickData.func.sourcetab;</instruction>
<instruction> Dlg.template = "dialog1";</instruction>
<instruction> Dlg.detach = true;</instruction>
<instruction> Dlg.Create();</instruction>
<instruction />
<instruction> var listview = Dlg.Control("listview1");</instruction>
<instruction> var i = listview.AddItem("Line 1");</instruction>
<instruction> listview.GetItemAt(i).subitems(0) = "L1.0";</instruction>
<instruction> listview.GetItemAt(i).subitems(1) = "L1.1";</instruction>
<instruction> i = listview.AddItem("Line 2");</instruction>
<instruction> listview.GetItemAt(i).subitems(0) = "L2.0";</instruction>
<instruction> listview.GetItemAt(i).subitems(1) = "L2.1";</instruction>
<instruction />
<instruction> Dlg.Show();</instruction>
<instruction> while (true)</instruction>
<instruction> {</instruction>
<instruction> var Msg = Dlg.GetMsg();</instruction>
<instruction> if (!Msg.result) break;</instruction>
<instruction> DOpus.Output("Msg Event = " + Msg.event);</instruction>
<instruction> if (Msg.event == "click" && Msg.control == "Autosize")</instruction>
<instruction> {</instruction>
<instruction> listview.columns.AutoSize();</instruction>
<instruction> }</instruction>
<instruction> }</instruction>
<instruction> DOpus.Output("Return code = " + Dlg.result);</instruction>
<instruction> }</instruction>
<instruction>}</instruction>
<instruction>==SCRIPT RESOURCES</instruction>
<instruction><resources></instruction>
<instruction> <resource name="dialog1" type="dialog"></instruction>
<instruction> <dialog fontsize="8" height="114" lang="english" resize="yes" standard_buttons="cancel" width="228"></instruction>
<instruction> <control height="84" name="listview1" nosortheader="yes" resize="wh" type="listview" viewmode="details" width="216" x="6" y="6"></instruction>
<instruction> <columns></instruction>
<instruction> <item text="Test Column 1" /></instruction>
<instruction> <item text="Test Column 2" /></instruction>
<instruction> <item text="Test Column 3" /></instruction>
<instruction> </columns></instruction>
<instruction> </control></instruction>
<instruction> <control height="14" name="Autosize" resize="y" title="Autosize" type="button" width="50" x="6" y="96" /></instruction>
<instruction> </dialog></instruction>
<instruction> </resource></instruction>
<instruction></resources></instruction>
</function>
</button>