Skip to main content

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

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

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.


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

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!


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

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!


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

This link is broken.


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

Try this one.


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

Thanks.