Invoke

  Good morning, can i make an invoke a method created in the form of events? For example:

  method-id button3_Click final private.
       01 newForm2 type CfgEmpresa.Form1.
       procedure division using by value sender as object e as type System.EventArgs.
           set newForm2             to new CfgEmpresa.Form1
           invoke newForm2::ShowDialog()
       end method.
   
  method-id ef-NumPedido_KeyPress final private.
       77 wt pic x(020).
       procedure division using by value sender as object e as type System.Windows.Forms.KeyPressEventArgs.
            move e::KeyChar to wt
           if wt equal "13"
              invoke button3_Click
           end-if
      
       end method.

method-id button3_Click final private.
       01 newForm2 type CfgEmpresa.Form1.
       procedure division using by value sender as object e as type System.EventArgs.
           set newForm2             to new CfgEmpresa.Form1
           invoke newForm2::ShowDialog()
       end method.
   
 method-id ef-NumPedido_KeyPress final private.
       77 wt pic x(020).
       procedure division using by value sender as object e as type System.Windows.Forms.KeyPressEventArgs.
            move e::KeyChar to wt
           if wt equal "13"
              invoke button3_Click
           end-if
      
       end method.

  • Verified Answer

    No, that wouldn't work because the event methods are expecting certain parameters such as the object that triggered the event and the eventargs. That is why the procedure division using header looks like:

    procedure division using by value sender as object e as type System.EventArgs

    It would probably make more sense to place the code that you want executed by both events into a common method of your own and then invoke this method from both event methods.

    Example:

    method-id button3_Click final private.
          procedure division using by value sender as object e as type System.EventArgs.
              invoke self::commonMethod
         end method.

    method-id ef-NumPedido_KeyPress final private.
          77 wt pic x(020).
          procedure division using by value sender as object e as type System.Windows.Forms.KeyPressEventArgs.
               move e::KeyChar to wt
              if wt equal "13"
                  invoke self::commonMethod    
              end-if
          end method.

    method-id commonMethod private.
          01 newForm2 type CfgEmpresa.Form1.
          procedure division.
              set newForm2             to new CfgEmpresa.Form1
              invoke newForm2::ShowDialog()
          end method.