System.InvalidOperationException. Use Form.ShowDialog Instea

Posted by Admin on 09-Feb-2010 03:26

I have a .cls splash screen (splash.cls) which has a button which when clicked runs our .w tree menu structure (treemenu.w). This all works fine.

I have the following code which runs a.cls file (aForm.cls) when double clicking an icon within our menu structure ....

DEFINE VARIABLE frm AS Cls.aForm NO-UNDO.

frm = NEW Cls.aForm().

WAIT-FOR System.Windows.Forms.Application:RUN (frm).

DELETE OBJECT frm.

I then get the following error pop-up. System.InvalidOperationException. Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog() Instead.

I'm aware the issue seems to be around having two cls files running as when I run aForm.cls without splash.cls running, aForm.cls runs fine. I'm just wondering how I go about using Form.ShowDialog and where?

I hope I've managed to make some sense here, I've attached some screenshots as well.

Any help would be greatly appreciated.

Thanks, Dez

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/19/Screenshots.doc:550:0]

All Replies

Posted by kevin_saunders on 09-Feb-2010 03:31

The rule is: One World, One WAIT-FOR..

The piece of code that invokes the splash.cls must have a WAIT-FOR System.Windows.Forms.Application:RUN() which is the only WAIT-FOR that you should have. Delete the WAIT-FOR in your tree menu program.

Posted by Admin on 09-Feb-2010 03:34

Hi Kevin,


If I remove the wait-for from the .w tree menu the menu closes as soon as it opens


Thanks, Dez

Posted by marko.rueterbories on 09-Feb-2010 04:55

Hi Derek,

did you delete the line "DELETE OBJECT frm." in your tree menu program aswell?

Regards, Marko

Posted by marko.rueterbories on 09-Feb-2010 04:55

sorry double posted

Posted by Admin on 09-Feb-2010 05:09

I don't think I've made myself clear sorry.


When I'm double clicking on the icon "run cls file" in the tree menu (see screenshot from first post) it is in affect running a .p called runner.p which calls aForm.cls. It is this file that contains....


DEFINE VARIABLE frm AS Cls.aForm NO-UNDO.

frm = NEW Cls.aForm().

WAIT-FOR System.Windows.Forms.Application:RUN (frm).

DELETE OBJECT frm.


....not the treemenu.w program itself.

Dez

Posted by Admin on 09-Feb-2010 05:12

FYI I tried removing the delete object frm from runner.p but I still get the same InvalidOperationException message.


Dez

Posted by Admin on 09-Feb-2010 05:18

If you start modal form (like ShowDialog() from System.Windows.Forms.Form class) you can try following code:

1. Insert into aForm class following public method:

METHOD PUBLIC VOID ShowModalDialog( ):

     WAIT-FOR THIS-OBJECT:ShowDialog().

END METHOD.

2. Use next code to launch modal aForm from your .w code:

DEFINE VARIABLE frm AS Cls.aForm NO-UNDO.

frm = NEW Cls.aForm().

frm:ShowModalDialog().

Bye!

Posted by Admin on 09-Feb-2010 05:22

You star!

Posted by Admin on 09-Feb-2010 06:12

Ivica.Loncar schrieb:

If you start modal form (like ShowDialog() from System.Windows.Forms.Form class) you can try following code:

1. Insert into aForm class following public method:

METHOD PUBLIC VOID ShowModalDialog( ):

     WAIT-FOR THIS-OBJECT:ShowDialog().

END METHOD.

2. Use next code to launch modal aForm from your .w code:

DEFINE VARIABLE frm AS Cls.aForm NO-UNDO.

frm = NEW Cls.aForm().

frm:ShowModalDialog().

Bye!

I'd rather not implement the ShowModalDialog method.

I'd prefer to be using the WAIT-FOR frm:ShowDialog () method directly in the .w file. A big benefit will be that you get access to the DialogResult:

/* in your .w file */

DEFINE VARIABLE oDialogResult AS System.Windows.Forms.DialogResult NO-UNDO.

WAIT-FOR frm:ShowDialog () SET oDialogResult.

IF Progress.Util.EnumHelper:AreEqual (oDialogResult, System.Windows.Forms.DialogResult:Ok) THEN

    ....

There's no real benefit in creating a public method that just calls another public method (and hides the result).

Posted by Admin on 11-Feb-2010 10:39

Hi Mike,


In terms of what I want to achieve what is advantage of having access to DialogResult (never heard of it sorry!)?


Thanks, Dez

Posted by Admin on 12-Feb-2010 03:16

Thank you Mike, your example works ok.

Do you have any idea how to start modeless forms (using Show() method) from .w file.

When i try that, WAIT-FOR frm:Show() method throws exception with progress error number 13967.

Posted by Admin on 12-Feb-2010 13:34

You need to use the .NET WAIT-FOR forehand. Basically you have to replace the WAIT-FOR CLOSE OF THIS-PROCEDURE from your main window (.w) with the

WAIT-FOR System.Windows.Forms.Application:Run () .

You need to create a dummy object first and use the System.Windows.Forms.Application:Exit() to terminate that WAIT-FOR. See my Bravepoint VI presentation, slide 12 for sample code.

http://www.consultingwerk.de/fileadmin/user_upload/pdf/OpenEdge%20GUI%20for%20.NET%20Adoption%20%26%20Migration%20Strategies.pdf

Posted by Alex_u4a on 16-Feb-2010 05:35

Hi Mike,

What's the dummy object for? My application seems to work fine with just the Application:Run().

Posted by Admin on 16-Feb-2010 05:40

What's the dummy object for? My application seems to work

fine with just the Application:Run().

That WAIT-FOR requires at least one .NET object before it's run. So I guess in your case, you'll have touched the .NET framework before using a different object.

Then you may ignore that.

Posted by Laura Stern on 16-Feb-2010 09:52

This was fixed in 10.2B.  You can now use the WAIT-FOR Application:Run() without having any forms or referencing anything in .NET before that point.

Posted by Admin on 16-Feb-2010 10:35

In terms of what I want to achieve what is advantage of having access to DialogResult (never heard of it sorry!)?

It's .NET's standard way of knowing in the caller if a Dialog was closed from an Ok, Cancel, Ignore, ... Button. A button on the Dialog Form might have the DialogResult property set.

It's a little by like an AUTO-GO or AUTO-END-KEY button in the ABL with more options to pick.

Posted by Admin on 30-Jul-2010 10:04

Hello,
I have another problem.
I have an MDI Form (FMenu.cls), which will dynamically calling several options menus.
If I open the form as you say here (showModalDialog), I can not press different menu options until you close the window, and I need to have more of an open form

Posted by Admin on 30-Jul-2010 11:20

If I open the form as you say here (showModalDialog), I can not press different menu options until you close the window, and I need to have more of an open form

See reply in your other thread on the same matter.

Posted by mkontwg on 05-Jan-2018 03:14

Hi Team

I have similar problem as well, im getting same error. tried above solution. Its seemed on my side my project folder structure not accurate. See below code;

//DEFINE VARIABLE hMain AS Client.Jason NO-UNDO.

               DEFINE VARIABLE hMain1 AS Client.Form1 NO-UNDO.

               IF(UserName:Text ="" OR Password:Text="") THEN DO:

                   MESSAGE " Password and Username is Incorrect"

                   VIEW-AS ALERT-BOX WARNING.

                   END.

              ELSE DO:

                  MESSAGE "Continue " VIEW-AS ALERT-BOX INFORMATION.

                  END.

                 /* this fires the next available window application

                  Once continued message is displayed.

                      */

                     hMain1 = NEW Client.Form1().

                      WAIT-FOR hMain:ShowDialog().

                      hMain1:Dispose().

The Client is my folder has file inside called Form1 and Jason.  Error "Name of the class in class statement 'Form1' must match the pattern of the name of the file 'Client\Form1.cls'"

Posted by Laura Stern on 05-Jan-2018 07:27

What is the name on the CLASS statement inside Form1.cls?  Look up whether you need Client. as part of the name.  Whatever the rule is, it sounds like you have it wrong.

Posted by mkontwg on 07-Jan-2018 23:16

Hi

Yes my rule was in correct, i have fixed non existing class that was sitting on .propath. It seem i have copied file manaully without being refreshing IDE. Thanks

This thread is closed