ShowDialog and Dispose issue

Posted by Lieven De Foor on 20-Apr-2011 07:51

Hi

10.2B04 is supposed to solve bug OE00203271: In an ABL form containing a dialog instantiated using "WAIT-FOR <dialog name>:Showdialog ()", the dialog can only be opened once. If the dialog is then closed and opened again, a System.ObjectDisposedException is thrown.

The MSDN documentation also states: "When a form is displayed as a modal dialog box, clicking the Close button (the button with an X at the upper-right corner of the form) causes the form to be hidden and the DialogResult property to be set to DialogResult.Cancel. Unlike non-modal forms, the Close method is not called by the .NET Framework when the user clicks the close form button of a dialog box or sets the value of the DialogResult property. Instead the form is hidden and can be shown again without creating a new instance of the dialog box. Because a form displayed as a dialog box is hidden instead of closed, you must call the Dispose method of the form when the form is no longer needed by your application." (http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx)

Yet when I try this my form is no longer available when ShowDialog returns.

The following code first shows a form non-modal, then halts for user input (modal using ShowDialog) and after that should be shown again as non-modal:

DEFINE VARIABLE MyForm AS Progress.Windows.Form NO-UNDO.


MyForm = NEW Progress.Windows.Form().

MyForm:Show().


MESSAGE "Processing..."

    VIEW-AS ALERT-BOX.

   

MyForm:Hide().

WAIT-FOR MyForm:ShowDialog().


MESSAGE "After ShowDialog"

    VIEW-AS ALERT-BOX.

   

MyForm:Show().


MESSAGE "Further processing..."

    VIEW-AS ALERT-BOX.

An exception is thrown when trying to Show() the form a second time:

System.ObjectDisposedException: Cannot access a disposed object.

This seems like an unsolved bug to me.

All Replies

Posted by jblitzie on 20-Apr-2011 08:17

Hi Leiven,

To fix the issue for all dialogs globally, I think you need to add the startup parameter  -nodialogdispose to your client session. There's also a new property on the form called disposeDialogOnClosed which defaults to TRUE. Set this to FALSE to control the behavior on a per form basis.

Jim

Posted by Lieven De Foor on 20-Apr-2011 08:25

Hi Jim,

I haven't tried the global option yet, but setting the property disposeDialogOnClosed to FALSE seems to do the trick, thanks for the quick solution!

This seems like a case where Progress wants to keep the default (buggy) behaviour to stay backwards compatible...

This thread is closed