208 views
in GUI Development by
Hi Gents,

 Have an issue with a menu button closing a modal when it is OnTap{} twice very quickly.

Code in question, I think, is:

      var Core::Root root = GetRoot();   
      root.EndModal(menuDialog);

Which throws a: "Runtime Core::Root.EndModal (6:3) : Chora exception: 'The group is not modal.'." when tapped twice in a row quickly. I must need a != null or something someplace...?

1 Answer

+1 vote
by

Hello Mike,

in this case the button fires twice and the corresponding code is executed twice. The first time, all works as expected. The dialog in question ends its modal state. All ok. The second time the operation fails since the dialog is not modal anymore. The error message indicates the problem. To eliminate this error, you can try following:

Option 1: Disable the button just in the moment when the first event is processed. This prevents the button from being able to fire twice. For example:

var Core::Root root = GetRoot();   
root.EndModal(menuDialog);

TheCloseButton.Enabled = false;

Option 2: Use a status variable where you track whether the dialog has been closed already. Perform EndModal() only if the variable is not yet set. For example:

if ( !DialogIsClosed )
{
  var Core::Root root = GetRoot();   
  root.EndModal(menuDialog);
  DialogIsClosed = true;
}

Alternative, if menuDialog is a variable use this variable for this purpose:

if ( menuDialog != null )
{
  var Core::Root root = GetRoot();   
  root.EndModal(menuDialog);
  menuDialog = null;
}

Option 3: Use the method GetModalGroup() to test whether the dialog in question is actually the top-most modal dialog.

var Core::Root root = GetRoot();   

if ( root.GetModalGroup() == menuDialog )
  root.EndModal(menuDialog);

Option 4: If the dialog in question is not the top-most modal dialog, the Option 3 will not work. In this case you can test the status of the dialog by using the method HasViewState(). For example:

if ( menuDialog.HasViewState( Core::ViewState.Modal ))
{
  var Core::Root root = GetRoot();   
  root.EndModal(menuDialog);
}

The above options demonstrate the possible approaches how to handle the situation. I hope one of them helps you to solve the issue. In this context I would also refer to the chapter Managing Dialogs and especially to the section Identify the active Dialogs and avoid race conditions. This documentation describe an alternative (to modal state) and more sophisticated technique to present dialogs and also provides dedicated functionality to detect and avoid possible race conditions.

Best regards

Paul Banach

Embedded Wizard Website | Privacy Policy | Imprint

...