You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Progress 4GL:内部过程finally块中缓冲记录不可用是否为预期行为?

Progress 4GL临时表缓冲区在finally块中不可用的问题及解决

现象说明

你编写的代码中,过程procedure1内定义的局部缓冲区btable1,在finally块中通过avail btable1检测时返回false,但临时表table1本身的avail检测返回true——即便此前通过该缓冲区创建过记录。

原因分析

在Progress 4GL的执行逻辑中:

  • 过程内定义的局部缓冲区属于过程的局部作用域元素,当流程进入finally块时,过程的局部变量(包括缓冲区)已经进入销毁阶段,此时avail检测会判定缓冲区不可用。
  • 临时表table1是在外部全局作用域定义的,其作用域覆盖调用过程,所以avail table1会正常返回true。

解决办法

针对这个问题,有几种可行的处理方式:

1. 将缓冲区移到过程外部定义

把缓冲区的定义放在过程之外,使其作用域覆盖finally块,这样就能在finally中正常访问:

define temp-table table1 no-undo
    field field1 as char
    . 
define buffer btable1 for table1. /* 缓冲区定义移至外部 */

run procedure1. 

procedure procedure1: 
    create btable1. 
    assign btable1.field1 = "Test". 

    find first table1. 

    finally: 
        message "Temp table available?:" avail table1 
                skip(1) 
                "Temp table buffer available?:" avail btable1
                skip(1)
                "Buffer record value:" btable1.field1
                view-as alert-box. 
    end finally. 
end procedure.

2. 在finally块中直接操作临时表默认缓冲区

不需要依赖局部缓冲区,直接通过临时表的默认缓冲区访问记录:

define temp-table table1 no-undo
    field field1 as char
    . 

run procedure1. 

procedure procedure1: 
    define buffer btable1 for table1. 

    create btable1. 
    assign btable1.field1 = "Test". 

    find first table1. 

    finally: 
        find first table1 no-error. /* 重新查找记录到默认缓冲区 */
        message "Temp table available?:" avail table1 
                skip(1) 
                "Temp table record available?:" avail table1
                skip(1)
                "Record value:" table1.field1
                view-as alert-box. 
    end finally. 
end procedure.

3. 提前缓存记录信息到变量

如果需要在finally块中使用缓冲区的记录数据,可以在过程执行时将数据存入局部变量,避免依赖缓冲区:

define temp-table table1 no-undo
    field field1 as char
    . 

run procedure1. 

procedure procedure1: 
    define buffer btable1 for table1. 
    define var cFieldValue as char no-undo.

    create btable1. 
    assign btable1.field1 = "Test"
           cFieldValue = btable1.field1. /* 缓存数据到变量 */

    find first table1. 

    finally: 
        message "Temp table available?:" avail table1 
                skip(1) 
                "Cached field value:" cFieldValue
                view-as alert-box. 
    end finally. 
end procedure.

内容的提问来源于stack exchange,提问作者user13093022

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 13:00:49