You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Sometimes programmers have a need to "save" the current values of fields and then restore then at some later time.
For instance a user may need to save the values of fields #A -> #C, and to do this you often code fields like this:
      define #sava reffld(#a)
      define #savb reffld(#b)
      define #savc reffld(#c)
and later .... (to save the values)
      change #sava #a
      change #savb #b
      change #savc #c
and still later .... (to restore the values)
 
      change #a #sava
      change #b #savb
      change #c #savc
 
An easier way to do this is to use a "working" list as a "stack" like this:
               def_list #stack (#a #b #c) type(*working) entrys(1)
to save the current values, "stack" them like this:
               inz_list #stack
to restore the values, "unstack" them like this:
               get_entry 1 #stack
Some other points about this technique are:

  • You can have as many "stacks" as you like.
  • The same field can be nominated in different stacks.
  • The resulting code is probably more efficient than the original
  • The stack can have more than 1 entry, allowing it to "stack" and "unstack" multiple different values. This is just like a true "stack" with "push" and "pull" facilities.
  • No labels