当前位置: 代码迷 >> 综合 >> 常识(4)- Yield()函数的作用
  详细解决方案

常识(4)- Yield()函数的作用

热度:75   发布时间:2023-12-08 12:31:38.0

 Yield()函数的作用

Yield()是一个不常用到的PowerBuilder函数。可是,在一个大的循环过程中,如果用户想在执行到一半时通过单击按钮或菜单来退出的话,就一定要用到Yield()函数了,否则程序只会在执行完成整个循环后才会响应按钮或菜单的Click事件。将Yield()函数放在循环体的中间。那么在循环执行的过程中发现有新的事件消息在消息队列中就回立即去响应。

Description
Yields control to other graphic objects, including objects that are not PowerBuilder objects. Yield checks the message queue and if there are messages in the queue, it pulls them from the queue.

Return value
Boolean. Returns true if it pulls messages from the message queue and false if there are no messages.

Usage
Include Yield within a loop so that other processes can happen. For example, use Yield to allow end users to interrupt a loop. By yielding control, you allow the user time to click on a cancel button in another window. Then code in the loop can check whether a global variable's status has changed. You can also use Yield in a loop in which you are waiting for something to finish so that other processing can take place, in either your or some other application.

Using other applications while retrieving data    Although the user cannot do other activities in a PowerBuilder application while retrieving data, you can allow them to use other applications on their system. Put Yield in the RetrieveRow event so that other applications can run during the retrieval.

Of course, Yield will make your PowerBuilder application run slower because processing time will be shared with other applications.

  相关解决方案