PB中PostEvent与TriggerEvent区别

PB中PostEvent与TriggerEvent区别postevent 函数是 post 消息 就是消息进入执行队列 不一定立即执行 而 triggerevent 是触发消息 程序立即响应 就这个区别 我觉得没什么例子可说啊 就是一个排队 一个插队的区别 也可以理解为同步执行 triggerevent 和异步执行 postevent nbsp PostEventPow

也可以理解为同步执行(triggerevent)和异步执行(postevent) 

PostEvent PowerScript function

Description

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

Controls

Any object, except the application object

Syntax

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

Argument

Description

objectname

The name of any PowerBuilder object or control (except an application) that has events associated with it.

event

A value of the TrigEvent enumerated datatype that identifies a PowerBuilder event (for example, Clicked!, Modified!, or DoubleClicked!) or a string whose value is the name of an event. The event must be a valid event for objectname and a script must exist for the event in objectname.

word (optional)

A long value to be stored in the WordParm property of the system’s Message object. If you want to specify a value for long, but not word, enter 0. (For cross-platform compatibility, WordParm and LongParm are both longs).

A long value or a string that you want to store in the LongParm property of the system’s Message object. When you specify a string, a pointer to the string is stored in the LongParm property, which you can access with the String function (see Usage).

Return Values

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.

You cannot post or trigger events for objects that do not have events, such as drawing objects. You cannot post or trigger events in a batch application that has no user interface because the application has no event queue.

After you call PostEvent, check the return code to determine whether PostEvent succeeded.

You can pass information to the event script with the word and long arguments. The information is stored in the Message object. In your script, you can reference the WordParm and LongParm fields of the Message object to access the information. Note that the Message object is saved and restored just before the posted event script runs so that the information you passed is available even if other code has used the Message object too.

If you have specified a string for long, you can access it in the triggered event by using the String function with the keyword “address” as the format parameter. (Note that PowerBuilder has stored the string at an arbitrary memory location and you are relying on nothing else having altered the pointer or the stored string.) Your event script might begin as follows:

string PassedString
PassedString = String(Message.LongParm, "address")

TriggerEvent and PostEvent are useful for preventing duplication of code. If two controls perform the same task, you can use PostEvent in one control’s event script to execute the other’s script, instead of repeating the code in two places. For example, if both a button and a menu delete data, the button’s Clicked script can perform the deletion and the menu’s Clicked event script can post an event that runs the button’s Clicked event script.

Choosing PostEvent or TriggerEvent

Both PostEvent and TriggerEvent cause event scripts to be executed. PostEvent is asynchronous; it adds the event to the end of an object’s event queue. TriggerEvent is synchronous; the event is triggered immediately.

Use PostEvent when you want the current event script to complete before the posted event script runs. TriggerEvent interrupts the current script to run the triggered event’s script. Use it when you need to interrupt a process, such as canceling printing.

If the function is the last line in an event script and there are no other events pending, PostEvent and TriggerEvent have the same effect.

Events and messages in Windows

Both PostEvent and TriggerEvent cause a script associated with an event to be executed. However, these functions do not send the actual event message. This is important when you are choosing the target object and event. The following background information explains this concept.

Many PowerBuilder functions send Windows messages, which in turn trigger events and run scripts. For example, the Close function sends a Windows close message (WM_CLOSE). PowerBuilder maps the message to its internal close message (PBM_CLOSE), then runs the Close event’s script and closes the window.

If you use TriggerEvent or PostEvent with Close! as the argument, PowerBuilder runs the Close event’s script but it does not close the window because it did not receive the close message. Therefore, the choice of which event to trigger is important. If you trigger the Clicked! event for a button whose script calls the Close function, PowerBuilder runs the Close event’s script and closes the window.

Use Post or Send when you want to trigger system events that are not PowerBuilder-defined events.

Examples

This statement adds the Clicked event to the event queue for CommandButton cb_OK. The event script will be executed after any other pending event scripts are run:

cb_OK.PostEvent(Clicked!)

This statement adds the user-defined event cb_exit_request to the event queue in the parent window:

Parent.PostEvent("cb_exit_request")

This example posts an event for cb_exit_request with an argument and then retrieves that value from the Message object in the event’s script.

The first part of the example is code for a button in a window. It adds the user–defined event cb_exit_request to the event queue in the parent window. The value 455 is stored in the Message object for the use of the event’s script:

Parent.PostEvent("cb_exit_request", 455, 0)

The second part of the example is the beginning of the cb_exit_request event script, which assigns the value passed in the Message object to a local variable. The script can use the value in whatever way is appropriate to the situation:

integer numarg
numarg = Message.WordParm

See Also

 

TriggerEvent PowerScript function

Description

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

Controls

Any object

Syntax

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

Argument

Description

objectname

The name of any PowerBuilder object or control that has events associated with it.

event

A value of the TrigEvent enumerated datatype that identifies a PowerBuilder event (for example, Clicked!, Modified!, or DoubleClicked!) or a string whose value is the name of an event. The event must be a valid event for objectname and a script must exist for the event in objectname.

word (optional)

A long value to be stored in the WordParm property of the system’s Message object. If you want to specify a value for long, but not word, enter 0. (For cross-platform compatibility, WordParm and LongParm are both longs.)

A long value or a string that you want to store in the LongParm property of the system’s Message object. When you specify a string, a pointer to the string is stored in the LongParm property, which you can access with the String function (see Usage).

Return Values

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.

Note Check return code

It is a good idea to check the return code to determine whether TriggerEvent succeeded and, based on the result, perform the appropriate processing.

You can pass information to the event script with the word and long arguments. The information is stored in the Message object. In your script, you can reference the WordParm and LongParm fields of the Message object to access the information.

If you have specified a string for long, you can access it in the triggered event by using the String function with the keyword “address” as the format parameter. Your event script might begin as follows:

string PassedString
PassedString = String(Message.LongParm, "address")

Note Caution

Do not use this syntax unless you are certain the long argument contains a valid string value.

For more information about events and when to use PostEvent and TriggerEvent, see PostEvent.

To trigger system events that are not PowerBuilder-defined events, use Post or Send, instead of PostEvent and TriggerEvent. Although Send can send messages that trigger PowerBuilder events, as shown below, you have to know the codes for a particular message. It is easier to use the PowerBuilder functions that trigger the desired events.

Equivalent syntax

Both of the following statements click the CheckBox cb_OK. The following call to the Send function:

Send(Handle(Parent), 273, 0, Long(Handle(cb_OK), 0))

is equivalent to:

cb_OK.TriggerEvent(Clicked!)

 

Examples

This statement executes the script for the Clicked event in the CommandButton cb_OK immediately:

cb_OK.TriggerEvent(Clicked!)
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/225154.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月17日 上午9:59
下一篇 2026年3月17日 上午9:59


相关推荐

  • python和c语言相通吗_C语言和Python有什么区别呢?

    python和c语言相通吗_C语言和Python有什么区别呢?展开全部 python 与 C 的区别如下 1 语言类型不同 Python 是一种动态类型语言 又是强类型语言 它们确定一个变量的类型是在 e69da5e887aa 您第一次给它赋值的时候 C 是静态类型语言 一种在编译期间就确定数据类型的语言 大多数静态类型语言是通过要求在使用任一变量之前声明其数据类型来保证这一点的

    2025年6月19日
    4
  • salt学习-grains

    salt学习-grainsgrains 作用 注 之所以叫 grain 就像凳子之所以被叫做凳子 也可以从翻译中理解 它的粒度很细 就是一个名字 只要理解这个名字后面代表的东西的功能和运用方式就可以了 在 salt 上存在一个接口 它被命名为 grains 接口 它被用于操作系统 域名 IP 地址 内核 操作系统类型 内存和许多其他系统属性的搜集 既然说这个接口会搜集系统的属性数据 那需要怎么查看呢 命令如下 使用

    2026年3月17日
    1
  • SQL数据库还原时备份集中的数据库备份与现有的数据库不同的解决办法

    SQL数据库还原时备份集中的数据库备份与现有的数据库不同的解决办法
    SQLServer2005数据库还原出错
    错误具体信息为:备份集中的数据库备份与现有的A数据库不同
    具体操作如下:
    第一次:新建了数据库A,数据库文件放在E:/DB/A目录下,选中该数据库右键-任务-还原-文件和文件组,在源设备中找到备份文件A.bak,目标数据库选中A,还原路径找到E:/DB/A目录下数据库文件(刚才所建数据库A的数据库文件),选择覆盖原数据库,点还原后出现错误:备份集中的数据库备份与现有的A数据库不同
    第二次:删除了数据库A,直接在

    2022年5月9日
    62
  • java查找字符的方法_Java字符串查找(3种方法)

    java查找字符的方法_Java字符串查找(3种方法)在给定的字符串中查找字符或字符串是比较常见的操作。字符串查找分为两种形式:一种是在字符串中获取匹配字符(串)的索引值,另一种是在字符串中获取指定索引位置的字符。根据字符查找String类的indexOf()方法和lastlndexOf()方法用于在字符串中获取匹配字符(串)的索引值。1.indexOf()方法indexOf()方法用于返回字符(串)在指定字符串中首次出现的索引位置,…

    2025年6月8日
    4
  • hdu1796 How many integers can you find

    hdu1796 How many integers can you find

    2022年1月8日
    48
  • 计算机win7卡顿如何解决方法,win7卡顿严重解决方法_win7运行卡顿严重最流畅设置方法-win7之家…[通俗易懂]

    计算机win7卡顿如何解决方法,win7卡顿严重解决方法_win7运行卡顿严重最流畅设置方法-win7之家…[通俗易懂]在使用win7系统电脑的时间一长,出现的电脑故障也就会越多,这大多数都是用户自己所造成的,例如有用户的win7系统在运行过程中总是会出现严重卡顿的情况,这让许多用户都感到很难受,那么win7卡顿严重怎么解决呢?下面小编就来告诉大家win7运行卡顿严重最流畅设置方法。具体方法:1、右击【计算机】选择属性;2、在出现的面板的左侧栏选择【高级系统设置】;3、依次点击【高级】【设置】;4、默认是【让系统选…

    2025年11月1日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号