常识(1)- TriggerEvent()/Event()/PostEvent()有什么不同

TriggerEvent()/Event()/PostEvent()有什么不同

在PB中经常要从一个事件中调用另外一个事件,常用的就是这几个函数

event把被调用事件放在最后面处理,可以带参数,也可以返回值,dynamic event()是其经典用法

注:Dynamic表示编译时指定事件可以不存在,系统把返回值类型检查推迟,到应用程序运行时进行。

triggerEvent触发指定对象的指定事件,是在事件队列的当前位置插入指定的事件,并且立即执行该事件中的脚本,它只能返回1,-1 或者空,带了long,word也比较麻烦

PostEvent在事件队列最后追加指定的事件,不是立即执行

-----

In PowerBuilder, there are several types of events.
System events with an ID:User actions or other system messages or a call in your scripts

System events without an ID:

User-defined events with an ID:User actions or other system messages or a call in your scripts

User-defined events without an ID:A call in your scripts

-----
objectname.TriggerEvent ( event {, word, long } )

Triggers an event associated with the specified object, which executes the script for that event immediately.

Return value
Integer.
Returns 1 if it is successful and the event script runs and -1 if the event is not a valid event for objectname, or no script exists for the event in  objectname. If any argument's value is null, TriggerEvent returns null.

Usage
If you specify the name of an event instead of a value of the TrigEvent enumerated datatype, enclose the name in double quotation marks.

-----
objectname.PostEvent ( event, { word, long } )

Adds an event to the end of the event queue of an object.

Return value
Boolean.
Returns true if it is successful and false if the event is not a valid event for objectnameobjectname. Also returns true if no script exists for the event in objectname. If any argument's value is null, PostEvent returns null.

Usage
You cannot post events to the event queue for an application object. Use TriggerEvent instead.

PowerBuilder messages or a call in your scripts

你可能感兴趣的:(常识(1)- TriggerEvent()/Event()/PostEvent()有什么不同)