Syntax

SET HANDLER handler1 handler2 ... FOR { oref |{ALL INSTANCES} } 
                                  [ACTIVATION act].

Extras:

1. ... FOR oref

2. ... FOR ALL INSTANCES

3. ... ACTIVATION act

Effect

This statement registers the event handlers handler1 handler2 ... for the associated instance events of the objects specified after FOR. The addition ACTIVATION can be used to deregister event handlers or perform a dynamic registration.

An event handler is raised if the associated instance event is raised using RAISE EVENT in an object for which it is registered. An event handler handler can be specified as follows, where the names have the same meaning as in the explicit method call:

  • meth
  • oref->meth
  • class=>meth

Methods meth can be specified from the same class or from other classes defined as instance event handlers using the addition FOR EVENT evt OF {class|intf} of the statements [CLASS-]METHODS. No event handlers for static events can be specified. At least one name must be specified.

The type class or intf specified after FOR EVENT OF in the definition of an instance event handler defines the objects whose events it can handle. Single objects or all handleable objects can be specified after FOR.

Addition 1

... FOR oref

Effect

This addition registers or deregisters the event handlers of the list handler1 handler2 ... for exactly one object. oref is an object reference that must point to an object whose events can be handled by the specified event handlers. The class of the object must be class or a subclass of class, or must implement the interface intf directly or through a superclass.

oref is a functional operand position.

Example

Registers an event handler for an ALV event.

CLASS demo DEFINITION.
PUBLIC SECTION.
METHODS main.
PRIVATE SECTION.
DATA itab TYPE TABLE OF scarr.
METHODS handle_double_click
FOR EVENT double_click OF cl_salv_events_table.
ENDCLASS. CLASS demo IMPLEMENTATION.
METHOD main.
DATA alv TYPE REF TO cl_salv_table.
...
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = alv
CHANGING t_table = itab ).
SET HANDLER handle_double_click FOR alv->get_event( ).
CATCH cx_salv_msg.
...
ENDTRY.
ENDMETHOD.
METHOD handle_double_click.
...
ENDMETHOD.
ENDCLASS.

  

Addition 2

... FOR ALL INSTANCES

Effect

This addition registers or deregisters the event handlers of the list handler1 handler2 ... for all objects whose events they can handle. These are all objects whose classes are either class or the subclass of class, or which implement the interface intf directly or through a superclass. A registration of this type is also valid for all raising instances created after the statement SET HANDLER.

Note

Registration with FOR ALL INSTANCES applies also in particular for temporary instances as they can be created when using the instantiaion operator NEW.

Addition 3

... ACTIVATION act

Effect

A single-character text-like field act can be specified after the addition ACTIVATION. If act has the value "X" (the default value), the event handlers handler are registered. If act has the value " ", however, the registration of the event handlers handler is canceled. A single registration cannot, on the other hand, be deregistered using mass deregistration. Conversely, individual raising objects cannot be excluded from registration after a mass registration.

Note

As long as the registration of an instance method as an event handler for an instance event is not canceled using ACTIVATION " " or all raising instances are deleted, the associated object cannot be deleted by the garbage collector. This is because it is still used by the runtime environment.

Example

Registers an event handler with FOR ALL INSTANCES. The events of all temporary instances created with NEW are handled until registration is stopped. The program can be executed as DEMO_SET_HANDLER_FOR_ALL.

CLASS cls DEFINITION.
PUBLIC SECTION.
EVENTS evt
EXPORTING VALUE(p) TYPE string DEFAULT `nop`.
METHODS meth
IMPORTING p TYPE string.
ENDCLASS. CLASS cls IMPLEMENTATION.
METHOD meth.
RAISE EVENT evt EXPORTING p = p.
ENDMETHOD.
ENDCLASS. CLASS hdl DEFINITION.
PUBLIC SECTION.
METHODS meth FOR EVENT evt OF cls
IMPORTING p.
ENDCLASS. CLASS hdl IMPLEMENTATION.
METHOD meth.
cl_demo_output=>write( p ).
ENDMETHOD.
ENDCLASS. START-OF-SELECTION.
DATA(href) = NEW hdl( ).
SET HANDLER href->meth FOR ALL INSTANCES. NEW cls( )->meth( `Ping 1`).
NEW cls( )->meth( `Ping 2`).
NEW cls( )->meth( `Ping 3`).

  

SET HANDLER href->meth FOR ALL INSTANCES ACTIVATION ' '.

NEW cls( )->meth( `Ping 4`). 
  NEW cls( )->meth( `Ping 5`). 
  NEW cls( )->meth( `Ping 6`).

cl_demo_output=>display( ).

SET HANDLER - FOR的更多相关文章

  1. android Handler介绍

    Handler使用介绍: Handler根据接收的消息,处理UI更新.Thread线程发出消息,通知Handler更新UI. Handler mHandler = new Handler() {  p ...

  2. Handler

    1.1 继承AbstractController优点:能定制请求方式 package cn.happyl.controller; import javax.servlet.http.HttpServl ...

  3. Android消息处理机制(Handler、Looper、MessageQueue与Message)

    Android是消息驱动的,实现消息驱动有几个要素: 消息的表示:Message 消息队列:MessageQueue 消息循环,用于循环取出消息进行处理:Looper 消息处理,消息循环从消息队列中取 ...

  4. Android笔记——Handler Runnable与Thread的区别

    在java中可有两种方式实现多线程,一种是继承Thread类,一种是实现Runnable接口:Thread类是在java.lang包中定义的.一个类只要继承了Thread类同时覆写了本类中的run() ...

  5. Android消息传递之Handler消息机制

    前言: 无论是现在所做的项目还是以前的项目中,都会遇见线程之间通信.组件之间通信,目前统一采用EventBus来做处理,在总结学习EventBus之前,觉得还是需要学习总结一下最初的实现方式,也算是不 ...

  6. Handler系列之内存泄漏

    本篇简单的讲一下平常使用Handler时造成内存泄漏的问题. 什么是内存泄漏?大白话讲就是分配出去的内存,回收不回来.严重会导致内存不足OOM.下面来看一下造成内存泄漏的代码: public clas ...

  7. Handler系列之创建子线程Handler

    上一篇我介绍了Handler机制的工作原理,默认情况下,ActivityThread类为我们创建的了主线程的Looper和消息队列,所以当你创建Handler之后发送消息的时候,消息的轮训和handl ...

  8. Handler系列之原理分析

    上一节我们讲解了Handler的基本使用方法,也是平时大家用到的最多的使用方式.那么本节让我们来学习一下Handler的工作原理吧!!! 我们知道Android中我们只能在ui线程(主线程)更新ui信 ...

  9. Handler系列之使用

    作为一个Android开发者,我们肯定熟悉并使用过Handler机制.最常用的使用场景是"在子线程更新ui",实际上我们知道上面的说话是错误的.因为Android中只有主线程才能更 ...

  10. 阶段一:用Handler和Message实现计时效果及其中一些疑问

    “阶段一”是指我第一次系统地学习Android开发.这主要是对我的学习过程作个记录. 本来是打算继续做天气预报的优化的,但因为某些原因,我要先把之前做的小应用优化一下.所以今天就插播一下用Handle ...

随机推荐

  1. Bootstrap 4/3 页面基础模板 与 兼容旧版本浏览器

    Bootstrap 3 与 4 差别很大,目录文件结构.所引入的内容也不同,这里说说一下 Bootstrap 引入的文件.网页模板和兼容性问题.本网站刚刚搭建好,正好发一下文章原来测试网站. Boot ...

  2. 沉淀再出发:Bean,JavaBean,POJO,VO,PO,EJB等名词的异同

    沉淀再出发:Bean,JavaBean,POJO,VO,PO,EJB等名词的异同 一.前言 想必大家都有这样的困惑,接触的东西越多却越来越混乱了,这个时候就要进行对比和深入的探讨了,抓住每一个概念背后 ...

  3. python基础语法2

    一.顺序结构 顺序结构就是从上而下的一步一步的执行每行程序语句. 二.分支结构(if) 形式1: if 条件: pass 形式2: if 条件: pass else: pass 形式3: if 条件: ...

  4. python基础语法1

    一.基础语法 1.常量 python语言没有真正的常量,它只是字面常量. 2.变量 变量是一个指针,它指向一块内存. 变量的命名规则: 1)只能包含字母.数字和下划线: 2)只能以字母或者下划线开始: ...

  5. 【重构.改善既有代码的设计】14、总结&读后感

    14.总结 首先,这是一本太老的书,很多观点已经被固化或者过时了.但核心观点没有问题,虽然大多数观点已经被认为是理所当然的事情了.   重构的定义 重构分几种: 1.狭义的代码重构   就是本书讲的, ...

  6. December 06th 2016 Week 50th Tuesday

    Behind every beautiful thing, there is some kind of pain. 美丽背后,必有努力. No pains, no gains. But it seem ...

  7. Tomcat服务时区设置

    tomcat服务不设置时间,会自动取系统时间,根据项目部署服务器位置不同时间会有差别,统一设置tomcat服务集群时间为东八区时间,具体设置如下: 在tomcat目录的bin文件夹下,找到文件cata ...

  8. Vmstat主要关注哪些数据?

    除特殊情况外,一般关注飘红部分 任务的信息(procs) r(running) 在internal时间段里,运行队列中的进程数,即表示正在运行或者正在等待CPU时间的进程数,如果这个参数值超过服务器上 ...

  9. 【OpenCV】【MFC】图片、视频、摄像头输入响应【详细图解】

    记住新建项目后,要配置OpenCV环境!参考链接http://blog.csdn.net/zy122121cs/article/details/49180541 做工程搭建框架什么的,基本的要熟练啊. ...

  10. springMVC <mvc:interceptors>拦截器的使用

    首先在springMVC.xml配置如下代码 <!-- 拦截器 --> <mvc:interceptors> <bean class="com.base.Acc ...