Data Entry State Handling

The following code is adapted from the program DoCst3 in the Example Application that ships with Zim. It is typical of older code found in Zim programs that handle data entry.

case
when $transmitkey in ("escape", "F3")
  if SaveFormChanged = $true
   DoChange ($true)
  endif
  break
when $transmitkey in ("F4", "F5")
  if SaveFormChanged = $true
   DoChange ($true)
   let SaveFormChanged = $false
  endif
  if $transmitkey = "F4"
   DoSelect ()
  else
   DoOrder (SaveFieldNum)
  endif
when $transmitkey in ("PageUp", "PageDown", "Home",
End")% Next,Previous,First,Last
  if SaveFormChanged = $true
   DoChange ($true)
   let SaveFormChanged = $false
  endif
  %% scroll in required direction
  ...
when $transmitkey = "F9"
  if SaveFormChanged = $true
   DoChange ($true)
   let SaveFormChanged = $false
  endif
  BrwCusts ()
  SetScroll ()
when $transmitkey = "F11" % Reset
  if SaveFormChanged = $true|
  DoChange ($true)
  let SaveFormChanged = $false
  endif
  find 0 Customers -> cset
  SetScroll ()
endcase

Note that the code "if SaveFormChanged ... endif" is repeated; the reason is as follows:

USING FRAMEWORK DATA ENTRY STATE HANDLING

As the above example illustrates, the status of a data entry window is defined by

Some actions require that any changes be committed first. In some cases, the user should be prompted first while there are other cases where the data should be committed unconditionally. The Framework pValidateAction program assists in tracking a windows status and can eliminate the need for much of the checking done in the above code. Here is the same code, rewritten to react to actions rather than $transmitkey and using pValidateAction.

%% pValidateAction handles all status checking.
 
let vlValidAction=$true vlNewState="" vlNewView=""
pValidateAction
(vlStatus, vlAction, \
 vCustState.stWindowName, vCustState.stView, \
 CustState.stState, vCustState.stModified, \
 vlNewView, vlNewState, vlValidAction)
if (vlValidAction = $false)
  return
endif
 
case
%% New "SAVE" action.
when vlAction = "SAVE"
  DoChange ()
  let vCustState.stModified = $false
when vlAction = "EXIT"
  break
when vlAction = "SELECT"
  DoSelect ()
when vlAction = "SORT"
  DoOrder (SaveFieldNum)
when vlAction = "SCROLL"
% Next,Previous,First,Last|
%% scroll in required direction
...
%% No need to do status checking in each case.
when vlAction = "BROWSE"
  BrwCusts ()
  SetScroll ()
when vlAction = "RESET"
  find 0 Customers -> cset
  SetScroll ()
endcase

Notes: