How do I only allowed one instance of dialog when scripting with Dialog

I've created a button with the following script , it'll show a new dialog each time when I click the button,

how do I get only one instance of the dialog even I click the button many times?

Function OnClick(ByRef clickData)
    Dim Dlg
    Set Dlg = DOpus.Dlg
    Dlg.Window = clickData.func.sourcetab
    Dlg.template = "MainDialog"
    Dlg.detach = True
    Dlg.want_close = True
End Function

Set a global/lister/tab (as desired) variable when the dialog is created and remove it when it's destroyed. You can then check if that is already set when creating the dialog.