如何在OpenEdge中使用LASTKEY

huangapple go评论48阅读模式
英文:

How to use LASTKEY in OpenEdge

问题

我刚刚花了差不多一整天的时间,试图理解为什么这段(简化版本的)代码不起作用:

DO WHILE NOT lUserQuit:
   DO ON ENDKEY UNDO, LEAVE:
      iIssueNumber = ?.
      UPDATE iIssueNumber
             GO-ON(RETURN F4 F6)
             WITH FRAME iIssueNumber-f
                  ROW 10
                  COLUMN 5
                  NO-LABELS.
      END.

   RUN WrtToLogfile("{&FILE-NAME}: {&LINE-NUMBER}: " +
                    "Issue number from keyboard: " +
                       STRING(iIssueNumber)) +
                    " KEYFUNCTION(LASTKEY):" +
                        cFunctionLastKey).

   IF KEYFUNCTION(LASTKEY) = "END-ERROR" THEN DO:
      lUserQuit = TRUE.
      iIssueNumber = ?.
      END.
   ELSE IF KEYFUNCTION(LASTKEY) = "F6" THEN DO:
      ....
      END.
   END.

这段代码似乎会导致调用WrtToLogfile函数后吞噬掉UPDATE留下的值,之后代码似乎再也无法看到它?PS,我相当确定通过事件驱动程序可以更好地完成这一切,但我支持的代码非常古老 如何在OpenEdge中使用LASTKEY (而我也是)。

(我有“ABL参考”PDF页面的LASTKEY函数在我的桌面上打开,它没有警告你这个问题!)

祝大家一切顺利...

Allan

英文:

I've just spent pretty well a whole day trying to understand why this (simplified version) didn't work;

DO WHILE NOT lUserQuit:
   DO ON ENDKEY UNDO, LEAVE:
      iIssueNumber = ?.
      UPDATE iIssueNumber
             GO-ON(RETURN F4 F6)
             WITH FRAME iIssueNumber-f
                  ROW 10
                  COLUMN 5
                  NO-LABELS.
      END.

   RUN WrtToLogfile("{&FILE-NAME}: {&LINE-NUMBER}: " +
                    "Issue number from keyboard: " +
                       STRING(iIssueNumber)) +
                    " KEYFUNCTION(LASTKEY):" +
                        cFunctionLastKey).

   IF KEYFUNCTION(LASTKEY) = "END-ERROR" THEN DO:
      lUserQuit = TRUE.
      iIssueNumber = ?.
      END.
   ELSE IF KEYFUNCTION(LASTKEY) = "F6" THEN DO:
      ....
      END.
   END.

(WrtToLogfile is a function which adds the value of its character expression argument to a logfile... not included for brevity!)

This code seems to be acting as if the call to WrtToLogfile gobbles up the value left by the UPDATE and from then on the code just never gets to see it after that?

PS I'm quite sure that this could all be done much better with an event driven program but the code I'm supporting is very old 如何在OpenEdge中使用LASTKEY (and so am I).

(I have the "ABL Reference" PDF page for the LASTKEY function open on my desktop and it doesn't warn you of this!)

Best wishes to everyone...

Allan

答案1

得分: 3

以下是翻译好的代码部分:

这段代码可以更好地说明发生了什么。如果运行下面的代码,您会看到LASTKEY可以安全地多次检查,并将继续显示预期值。

    define variable something as character no-undo.
    define variable nothing   as character no-undo.
    define variable allDone   as logical   no-undo.
    define variable step      as character no-undo.
    define variable kvalue    as integer   no-undo format "->>>9".
    define variable kf        as character no-undo format "x(20)".
    define variable kl        as character no-undo format "x(20)".
    
    form
      step kvalue kf kl skip
     with
      frame b
      down
      no-box
    .
    
    do while allDone = no:
    
      allDone = no.
    
      do on endkey undo, leave:
    
        update
          something go-on( return f4 f6 )
         with
          frame a
        .
    
        display "1" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
        down with frame b.
    
        run logsomething.
    
        display "2" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
        down with frame b.
    
        if keyfunction( lastkey ) = "end-error" then do:
    
          display "3" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
          down with frame b.
    
          allDone = yes.
          something = ?.
    
        end.
        else if keyfunction( lastkey ) = "f6" then do:
    
          display "4" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
          down with frame b.
    
        end.
    
      end.
    
      display "5" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
      down with frame b.
    
    end.
    
    procedure logsomething:
    
      display "1a" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
      down with frame b.
    
      output to value( "something.log" ).
      put lastkey skip.
      output close.
    
      display "1b" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
      down with frame b.
    
      input from value( "something.log" ).
      import nothing.
      input close.
    
      display "1c" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
      down with frame b.
    
      return.
    
    end.

希望这有助于您理解代码。如果需要进一步帮助,请随时提问。

英文:

This code might help to better illustrate what is going on. If you run the code below you will see that LASTKEY can be safely checked many times and will continue to show the expected value.

define variable something as character no-undo.
define variable nothing   as character no-undo.
define variable allDone   as logical   no-undo.
define variable step      as character no-undo.
define variable kvalue    as integer   no-undo format "->>>9".
define variable kf        as character no-undo format "x(20)".
define variable kl        as character no-undo format "x(20)".

form
  step kvalue kf kl skip
 with
  frame b
  down
  no-box
.

do while allDone = no:

  allDone = no.

  do on endkey undo, leave:

    update
      something go-on( return f4 f6 )
     with
      frame a
    .

    display "1" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
    down with frame b.

    run logsomething.

    display "2" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
    down with frame b.

    if keyfunction( lastkey ) = "end-error" then do:

      display "3" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
      down with frame b.

      allDone = yes.
      something = ?.

    end.
    else if keyfunction( lastkey ) = "f6" then do:

      display "4" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
      down with frame b.

    end.

  end.

  display "5" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
  down with frame b.

end.

procedure logsomething:

  display "1a" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
  down with frame b.

  output to value( "something.log" ).
  put lastkey skip.
  output close.

  display "1b" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
  down with frame b.

  input from value( "something.log" ).
  import nothing.
  input close.

  display "1c" @ step lastkey @ kvalue keyfunction( lastkey) @ kf keylabel( lastkey) @ kl with frame b.
  down with frame b.

  return.

end.

In the output below I typed "abc" followed bt RETURN, then "def" followed by F6 and then, finally F4:

step     kvalue kf                   kl
──────── ────── ──────────────────── ────────────────────
1            13 RETURN               RETURN
1a           13 RETURN               RETURN
1b           13 RETURN               RETURN
1c           13 RETURN               RETURN
2            13 RETURN               RETURN
5            13 RETURN               RETURN
1           306 PUT                  F6
1a          306 PUT                  F6
1b          306 PUT                  F6
1c          306 PUT                  F6
2           306 PUT                  F6
5           306 PUT                  F6
5           404 END-ERROR            PF4

What you are seeing is that, for F6, the KEYFUNCTION is "PUT" not, "F6". So your logic checking for F6 is always going to miss it. The KEYLABEL is "F6".

Additionally the F4 key is treated as END-ERROR and handled by the "DO ON ENDKEY..." rather than the GO-ON. So that block of logic also gets skipped.

huangapple
  • 本文由 发表于 2023年6月1日 02:25:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76376351.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定