Quantcast
Channel: Visual COBOL - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4356

Visual Cobol - Event Handler (Visual Studio)

$
0
0

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

Viewing all articles
Browse latest Browse all 4356

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>