NETJVM 

The DETACH Statement

Detaches a delegate or a method group from an event.

General Formats

DETACH Statement

Syntax Rules

  1. event-expression must evaluate to an EVENT.
  2. delegate-instance must be an expression that evaluates to a delegate type of the same type as event-expression.
  3. method-group must specify a method that is compatible with the delegate type of event-expression.

General Rules

  1. If the delegate-instance or method has previously been attached to the specified event, then it will be detached, and no longer executed when the event is executed.

Example

       class-id. AttachExample.
       01 changeCount1 binary-long static.
       01 changeCount2 binary-long static.

       method-id. main static.
       01 names type myList.
       01 del type ChangeDelegate.
       procedure division.
           set names to new myList
           attach method self::ListChanged1 to names::ChangeEvent
           set del to method self::ListChanged2
           attach del to names::ChangeEvent
           move 0 to changeCount1
           move 0 to changeCount2
           invoke names::"Add"("Max")
           invoke names::"Add"("Hector")
           invoke names::"Add"("Rover")
           invoke names::"Add"("Spot")
           if changeCount1 = 4
           and changeCount2 = 4
               display "Pass"
           else
               display "Fail"
           end-if
           detach del from names::ChangeEvent
           move 0 to changeCount1
           move 0 to changeCount2
           invoke names::"Add"("A")
           invoke names::"Add"("B")
           invoke names::"Add"("C")
           invoke names::"Add"("D")
           if changeCount1 = 4
           and changeCount2 = 0
               display "Pass"
           else
               display "Fail"
           end-if
           detach method self::ListChanged1 from names::ChangeEvent
           move 0 to changeCount1
           move 0 to changeCount2
           invoke names::"Add"("A")
           invoke names::"Add"("B")
           invoke names::"Add"("C")
           invoke names::"Add"("D")
           if changeCount1 = 0
           and changeCount2 = 0
               display "Pass"
           else
               display "Fail"
           end-if
       end method main.

       method-id ListChanged1 static(i1 as binary-long) static.
           add i1 to changeCount1
       end method.

       method-id. ListChanged2 (i1 as binary-long) static.
           add i1 to changeCount2
       end method.
       end class.

       class-id  myList.
       01 my-list List[string].
       01 ChangeEvent type ChangeDelegate event public.

       method-id. new.
           create my-list
       end method new.

       method-id Add (s as string).
           write my-list from s
           if ChangeEvent not = null
                invoke ChangeEvent(1)
           end-if
       end method.
       end class.

       delegate-id. ChangeDelegate (x1 as binary-long).
       end delegate ChangeDelegate.