如何遍历使用缓冲区访问的临时表?

时间:2016-03-31 07:41:05

标签: progress-4gl

我找到了一个article,关于从类外部访问类中声明的临时表。 我正在尝试使用第二种解决方案(使用句柄和缓冲区)。虽然它可以工作(我可以从中获取第一个或最后一个元素),但我无法找到迭代完整临时表的方法。

谢谢。

1 个答案:

答案 0 :(得分:2)

您可以通过创建动态查询并将其附加到缓冲区句柄来实现:

Class2.cls看起来完全一样,如果在下面添加它以供参考。

Test2.p已更改:

DEF VAR c-class2 AS Class2.

DEF VAR local-ttbuf-hdl AS HANDLE.
DEF VAR tt-def-buff AS HANDLE.

c-class2 = NEW Class2().
local-ttbuf-hdl = c-class2:GetTempTableHandle().
tt-def-buff = local-ttbuf-hdl:DEFAULT-BUFFER-HANDLE.


/*
/* Find last is commented out */
tt-def-buff:FIND-LAST().

MESSAGE tt-def-buff:BUFFER-FIELD(1):buffer-value SKIP
        tt-def-buff:BUFFER-FIELD(2):buffer-value
        VIEW-AS ALERT-BOX.

*/

/**** New code here ****/
/* Define and create a dynamic query */
DEFINE VARIABLE hQuery AS HANDLE      NO-UNDO.
CREATE QUERY hQuery.

/* Set the buffer */
hQuery:SET-BUFFERS(tt-def-buff).

/* Create a query-string */
hQuery:QUERY-PREPARE("FOR EACH " + tt-def-buff:NAME).

/* Open the query */
hQuery:QUERY-OPEN.


REPEAT :

    /* Get the next record, for the first run it will be the first record */
    hQuery:GET-NEXT().

    /* Leave the repeat if there are no more records */
    IF hQuery:QUERY-OFF-END THEN LEAVE.

    /* Display */
    MESSAGE tt-def-buff:BUFFER-FIELD(1):buffer-value SKIP
            tt-def-buff:BUFFER-FIELD(2):buffer-value
            VIEW-AS ALERT-BOX.

END.

/* All created objects should be deleted */
DELETE OBJECT hQuery.

Class2.cls:

CLASS class2:
   DEF VAR i AS INTEGER.
   DEF TEMP-TABLE tt
          FIELD i1 AS INTEGER
          FIELD c1 AS CHARACTER.

   CONSTRUCTOR class2():
        DO i = 1 TO 10:
             CREATE tt.
             ASSIGN
                 tt.i1 = i
                 tt.c1 = STRING(i).
        END.
   END CONSTRUCTOR.

   METHOD PUBLIC HANDLE GetTempTableHandle():
        RETURN TEMP-TABLE tt:HANDLE.
   END.
END CLASS.