Highlighted
Absent Member.
Absent Member.
2486 views

Translate fom C# to visual cobol

Jump to solution

I have a c# code lite this:

MyWindow.Closed += new EventHandler(MyWindowClosed)

What Code is this in Visual Cobol?

 

Best Regards

Bernd Riemke

0 Likes
2 Solutions

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Translate fom C# to visual cobol

Jump to solution

You can do this like:

   attach method self::MyWindowClosed to self::Closed

Or you can select the Closed event on the Window from the Properties page and place the event handler name there.

View solution in original post

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Translate fom C# to visual cobol

Jump to solution

No I tested this with 2.1 update 1 and it works fine.
Here is the example that I am using.

Here is the code for Window 1 which is in a WPF application project:

       class-id WPFWindows1.Window1 is partial
                 inherits type System.Windows.Window.

       working-storage section.
       01 mywindow2 type WPFWindows2.Window2.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent()
           goback.
       end method.

       method-id Window_Closed2.
       procedure division using by value sender as object e as type System.EventArgs.
          set self::txtParam::Text to mywindow2::myfield
       end method.

       method-id Button_Click.
       procedure division using by value sender as object e as type System.Windows.RoutedEventArgs.
           set mywindow2 to new WPFWindows2.Window2
           invoke mywindow2::add_Closed(new EventHandler(self::Window_Closed2))
           *>attach method self::Window_Closed2 to mywindow2::Closed
           invoke mywindow2::Show
       end method.

       end class.

and the code for Windows 2 which is in a WPF library:

       class-id WPFWindows2.Window2 is partial
                 inherits type System.Windows.Window.

       working-storage section.
       01 myfield  string property.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent()
           set self::txtParam::Text to "Enter Name"
           goback.
       end method.

       method-id Button_Click.
       procedure division using by value sender as object e as type System.Windows.RoutedEventArgs.
           set myfield to self::txtParam::Text
           invoke self::Close
       end method.

       end class.

View solution in original post

0 Likes
7 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Translate fom C# to visual cobol

Jump to solution

You can do this like:

   attach method self::MyWindowClosed to self::Closed

Or you can select the Closed event on the Window from the Properties page and place the event handler name there.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Translate fom C# to visual cobol

Jump to solution

This give me an error back..

attach method self::MyWindowClosed to MyWindow::Closed

MyWindow is a second window that is closed...

After the second window is closed i will do something...

Best Regards

Bernd Riemke

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Translate fom C# to visual cobol

Jump to solution

This is the errorcode:

COBCH852 : System error - unexpected error while generating managed code C:\\WPFWindows\Window1.xaml.cbl 24 1 WPFWindows

Best Regards

Bernd Riemke

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Translate fom C# to visual cobol

Jump to solution

Sorry, there was a problem with using the attach syntax when the event handler was for an object in a different project.

I was testing using VC 2.2 which will be released soon and has this problem fixed.

Try this syntax instead:

    invoke MyWindow::add_Closed(new EventHandler(self::MyWindowClosed))

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Translate fom C# to visual cobol

Jump to solution

Ok...

invoke MyWindow::add_Closed(new EventHandler(self::MyWindowClosed))

give me an error that he not founf the method...

Is this a bug in VC 2.1 and is this fixed in VC 2.2 ?

Or how must the method "MyWindowClosed" build?

Best Regards

Bernd Riemke

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Translate fom C# to visual cobol

Jump to solution

No I tested this with 2.1 update 1 and it works fine.
Here is the example that I am using.

Here is the code for Window 1 which is in a WPF application project:

       class-id WPFWindows1.Window1 is partial
                 inherits type System.Windows.Window.

       working-storage section.
       01 mywindow2 type WPFWindows2.Window2.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent()
           goback.
       end method.

       method-id Window_Closed2.
       procedure division using by value sender as object e as type System.EventArgs.
          set self::txtParam::Text to mywindow2::myfield
       end method.

       method-id Button_Click.
       procedure division using by value sender as object e as type System.Windows.RoutedEventArgs.
           set mywindow2 to new WPFWindows2.Window2
           invoke mywindow2::add_Closed(new EventHandler(self::Window_Closed2))
           *>attach method self::Window_Closed2 to mywindow2::Closed
           invoke mywindow2::Show
       end method.

       end class.

and the code for Windows 2 which is in a WPF library:

       class-id WPFWindows2.Window2 is partial
                 inherits type System.Windows.Window.

       working-storage section.
       01 myfield  string property.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent()
           set self::txtParam::Text to "Enter Name"
           goback.
       end method.

       method-id Button_Click.
       procedure division using by value sender as object e as type System.Windows.RoutedEventArgs.
           set myfield to self::txtParam::Text
           invoke self::Close
       end method.

       end class.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Translate fom C# to visual cobol

Jump to solution

Thats nearly what I Need!

Many thanks Chris!

Best Regards

Bernd Riemke

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.