Highlighted
Absent Member.
Absent Member.
2663 views

Visual Cobol - Event Handler (Visual Studio)

Jump to solution

Hello!

I have 2 problems with an event handler.

1: I am implementing the interface ICommand and Visual Stuido tells me that the interface member CanExecuteChanged or one of its overloads is not implemented.

2: I know how to write custom set and get methods for properties in cobol, in c# I can do the same for properties but also can I write custom add and remove methods for event handlers, but how can i achieve this in cobol?

My C# code i want to translate to cobol code:

class RelayCommand : ICommand
    {
        private readonly Action<object> _execute;
        private readonly Predicate<object> _canExecute;
        public RelayCommand(Action<object> execute)
            : this(execute, null)
        {
        }
        public RelayCommand(Action<object> execute, Predicate<object> canExecute)
        {
            if (execute == null)
                throw new ArgumentNullException("execute");
            _execute = execute;
            _canExecute = canExecute;
        }
        public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute(parameter);
        }
        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }
        public void Execute(object parameter)
        {
            _execute(parameter);
        }
    }

So far my cobol code is:

class-id. RelayCommand as "wpfTest1.Commands.RelayCommand" implements type "System.Windows.Input.ICommand".
                
        environment division.
        configuration section.
        repository.
            .
        static.
        working-storage section.
        end static.
        object.
        working-storage section.
        01 _execute                 type "System.Action"[type "System.Object"] private.
        01 _canExecute              type "System.Predicate"[type "System.Object"] private.
        01 CanExecuteChanged        type "System.EventHandler" event public as "CanExecuteChanged".
        
        method-id. "New".
        procedure division using by value oExecute as type "System.Action"[type "System.Object"].
        
            invoke self::"New"(oExecute, null)
        end method "New".
        
        method-id. "New".
        procedure division using by value oExecute as type "System.Action"[type "System.Object"]
                                          lCanExecute as type "System.Predicate"[type "System.Object"].
            
            if oExecute = null
                raise type "System.ArgumentNullException"::"New"("_execute")
            end-if
            
            set _execute to oExecute
            set _canExecute to lCanExecute 
        end method "New".
        method-id. "CanExecute" public.
        procedure division using by value oParameter as type "System.Object"
                                returning lRes as condition-value.
                       
            if self::"_canExecute" = null
                set lRes to true
            else
                set lRes to self::"_canExecute"::"Invoke"(oParameter)
            end-if
            
        end method "CanExecute".
        
        method-id. "Execute" public.
        procedure division using by value oParameter as type "System.Object".
            invoke self::"_execute"::"Invoke"(oParameter)
        end method "Execute".
        end object.
end class RelayCommand.

Thanks in advance for any help.

Best regards,
Thomas
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Visual Cobol - Event Handler (Visual Studio)

Jump to solution

The problem that you are reporting sounds very much like an issue that I dealt with previously that has been fixed in the upcoming Visual COBOL 2.2 release.

Please contact Micro Focus Customer Care and create a support incident for this problem so that we can recreate it and report it to development and test that it is the same problem.

In later releases of Visual COBOL we have added support for the ATTACH and DETACH statements in order to better facilitate the use of setting event handlers.

Please see the managed code reference section of the documentation covering delegates and events for syntax examples of using these statements here.

Thanks.

View solution in original post

0 Likes
5 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Visual Cobol - Event Handler (Visual Studio)

Jump to solution

The problem that you are reporting sounds very much like an issue that I dealt with previously that has been fixed in the upcoming Visual COBOL 2.2 release.

Please contact Micro Focus Customer Care and create a support incident for this problem so that we can recreate it and report it to development and test that it is the same problem.

In later releases of Visual COBOL we have added support for the ATTACH and DETACH statements in order to better facilitate the use of setting event handlers.

Please see the managed code reference section of the documentation covering delegates and events for syntax examples of using these statements here.

Thanks.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Visual Cobol - Event Handler (Visual Studio)

Jump to solution

Thanks for the answer - I already notcied there are ATTACH and DETACH statements, but unforunately these are not supported in the cobol version we use.

I will see that i report that issue.

Thanks!

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

RE: Visual Cobol - Event Handler (Visual Studio)

Jump to solution

This link is broken.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Visual Cobol - Event Handler (Visual Studio)

Jump to solution

Try this one.

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

RE: Visual Cobol - Event Handler (Visual Studio)

Jump to solution

Thanks.

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.