home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a054 / 1.img / GETEXS.EXE / GETEX.TXT next >
Encoding:
Text File  |  1992-03-17  |  8.9 KB  |  257 lines

  1.                               Get Paper Exercises
  2.  
  3.  
  4. SECTION 1
  5. ------------------------------------------------------------------------------
  6.  
  7. 1. What problems exist with using local GetLists to implement nested
  8.    reads?
  9.  
  10.    If routines called from either a when clause, valid clause, or
  11.    hot keys need to access the currently active get objects, they 
  12.    cannot simply refer to GetList; it is local to the routine performing
  13.    the nested read. See page 17 and 18 for more detail and suggested
  14.    ways of overcoming it.
  15.  
  16.  
  17. 2. What's the problem with the following attempt at declaring a local
  18.    GetList for nested reads?
  19.  
  20.      LOCAL GetList
  21.  
  22.    The problem is that the declaration does not declare GetList as an array.
  23.    It creates a variable, getList, whose type is undefined and whose value
  24.    is NIL. Subsequent GET commands, which the preprocessor has translated to
  25.    Aadd(GetList, _GET_(....) ) will thus fail.
  26.  
  27.    You must declare GetList with:
  28.  
  29.      LOCAL GetList := {}
  30.  
  31.  
  32. 3. What are the advantages of using code blocks for WHEN and VALID clauses?
  33.  
  34.    The blocks are passed the current get object as a parameter. They can thus
  35.    process it without regard for which array it is contained within (see
  36.    1 above), and there is no problem validating array elements (Section
  37.    2 discusses how VALID a[i] ... will fail at run-time because of the
  38.    value of i when the valid clause is evaluated).
  39.  
  40.    Another advantage is you can pass the entire array of get objects to
  41.    the valid routine. This avoids the problem with nesting GetList as
  42.    described in exercise 1 in this section.
  43.  
  44.  
  45. 4. What are the advantages of using teh SetKey function rather than the
  46.    SET KEY command?
  47.  
  48.    The Principles paper discusses this in detail. The advantage here,
  49.    pertaining to the Get object class, is you can pass the entire array
  50.    of get objects to the function, thus avoiding the problems pointed
  51.    out in exercise 1 in this section.
  52.  
  53.  
  54. SECTION 2
  55. ------------------------------------------------------------------------------
  56.  
  57. 2. What is the difference between:
  58.  
  59.      Eval(Get:block)
  60.  
  61.    and:
  62.  
  63.      Get:varGet()  ?
  64.  
  65.  
  66.    In most cases, they are the same. Both return the contents of the
  67.    variable or field which is the subject of the Get. The difference,
  68.    however, occurs when the theing being "got", is an element of an array.
  69.    Simply evaluating Get:block will only return a reference to the array;
  70.    Get:varGet(), however, returns the contents of the array, as expected.
  71.    Refer to the section discussing Get:varGet() for more details, and also
  72.    look up its description in Nantucket's Norton Guides file (Note the
  73.    printed documentation does not mention Get:varGet()).
  74.  
  75.  
  76. 3. How can you write a valid clause to validate the variable entered when
  77.    the variable refers to an array element?
  78.  
  79.    This question refers to the fact that if you issue gets in a loop,
  80.    using arrays to hold variables, the validation clause will fail, as in:
  81.  
  82.      LOCAL aGetVars := {......}
  83.        ...
  84.        DO WHILE i <= Len(aGetVars)
  85.          @ ... GET aGetVars[i] VALID aGetVars[i] > 0
  86.  
  87.    The problem is that when the valid clause is evaluated, during the READ
  88.    command (ReadModal), the value of i is invalid, and the run-time
  89.    system produces a run-time error.
  90.  
  91.    The solution is to specify a code block directly for the valid clause,
  92.    and use Get:varGet(), as in:
  93.  
  94.          @ ... GET aGetVars[i] VALID {|oGet| oGet:varGet() > 0 }
  95.  
  96.    See the section on Get:varGet() for more details, and the section on
  97.    GETs and Arrays for a discussion of how to solve a similar problem with
  98.    WHEN clauses referring to array elements.
  99.  
  100.  
  101. 4. What does Get:subscript contain when you issue a get on aVar[4]? What
  102.    does it contain when you issue a get on aVar[4, 5].
  103.  
  104.    In the first case it contains {4}, in the second case {4, 5}. In both
  105.    cases, then, get:sunscript contains an array. This is different from
  106.    the documentation in Nantucket's Norton Guides which says if the
  107.    array element you are getting is a single dimension, Get:subscript
  108.    will not be an array. This is incorrect; Get:subscript is always an
  109.    array.
  110.  
  111.  
  112. 5. Consider the following code block:
  113.  
  114.      {|| Test(&Stri) }
  115.  
  116.    Compile and run this program without linking a function test. Comment on
  117.    the result. When and how does Clipper compile the expression defined by
  118.    the macro operator?
  119.  
  120.    The program links fine without the function Test. This implies that 
  121.    the entire code block is compiled at run-time using the macro operator.
  122.    If this were not the case, the compiler would have generated an external
  123.    request for the function Test, and the linker would complain about an
  124.    "Unresolved external".
  125.  
  126.    It appears that Clipper handles macros inside code blocks in three
  127.    different ways:
  128.  
  129.      {|| &i }   - Early macro expansion
  130.      {|| &(i) } - Late macro expansion
  131.      {|| more complex expansion } - Whole thing at compile-time
  132.  
  133.    If you do not understand the diffrence between early and late macro expansion,
  134.    refer to the Principles paper
  135.  
  136.  
  137. SECTION 3
  138. ------------------------------------------------------------------------------
  139.  
  140. 1. Why should you pass your array of get objects to WHEN and Valid clauses?
  141.  
  142.    This is so that if you nest reads using a local GetList, your when
  143.    and valid clause routines can refer to the entire list of gets. They
  144.    would be inaccesible, otherwise.
  145.  
  146.  
  147. 2. What are the problems with using a hard coded subscript to index the
  148.    public GetList array in functions called from WHEN and VALID clauses?
  149.  
  150.    The position of the get may change as you modify the program, and
  151.    the code is difficult to read. A better approach is to search the
  152.    GetList to determine the get number you want.
  153.  
  154.  
  155. 3. Modify program 8 (on disk as Gets04.prg) to use Get:cargo as a dictionary.
  156.  
  157.    See Getex01.prg
  158.  
  159.  
  160. 4. Modify program 9 (on disk as Gets05.prg) to only display the prompts
  161.    for the starting and ending page numbers when range is selected
  162.  
  163.    See Getex02.prg
  164.  
  165.  
  166. 5. How can you implement read only gets? That is, gets that are displayed
  167.    like regular gets but that you cannot change.
  168.  
  169.    This is easy. Simply create a WHEN clause containing a false!
  170.  
  171.  
  172. SECTION 4
  173. ------------------------------------------------------------------------------
  174.  
  175. 2. What does ReadModal return?
  176.  
  177.    It returns whether any gets were updated during the read. Thus, you
  178.    can replace:
  179.  
  180.      READ
  181.      IF Updated()
  182.        ...
  183.  
  184.    with:
  185.  
  186.      IF ReadModal(GetList)
  187.        ...
  188.  
  189.    if you really want to! Don't forget to clear GetList somewhere,
  190.    however.
  191.  
  192.  
  193. 3. How does the read system handle the stacking of static variables when
  194.    you call ReadModal recursively during a nested read?
  195.  
  196.    Upon entry, Readmodal calls ClearGetSysVars to save and clear the
  197.    static variables, and before returning it calls RestoreGetSysVars
  198.    to restore them. ClearGetSysVars returns an array containing the
  199.    current values of the statics, and ReadModal saves this in a LOCAL
  200.    variable, saveGetSysVars. It passes this local variable to
  201.    RestoreGetSysVars. The important point here is this saved array
  202.    is local. Thus, Clipper's run-time system is perform the stacking.
  203.  
  204.  
  205. 4. Where is the cursor positioned after a READ command? Why is this?
  206.  
  207.    It is positioned on the last but one row, at column 0 (!). This is
  208.    for compatability with Summer '87, apparently!
  209.  
  210.  
  211. 5. How can you change the default read system so that ReadVar includes
  212.    subscripts when the get variable is an arrau element?
  213.  
  214.    Compile getsys defining the symbol SUBSCRIPT_IN_READVAR, and uncomment
  215.    the conditional compilation in GetReadVar().
  216.  
  217.  
  218. 6. What does the default read system do with the Ctrl-w key? How about
  219.    Ctrl-End? Can you change this behaviour?
  220.  
  221.    Getsys is programmed so that both these keys terminate the READ.
  222.    You can change this so they both go to the last get, by compiling
  223.    Getsys defining the symbol CTRL_END_SPECIAL.
  224.  
  225.  
  226.  
  227. SECTION 6
  228. ------------------------------------------------------------------------------
  229.  
  230. 1. Implement a reader for dates that allows the user to use the + and -
  231.    keys to increment and decrement the date field or variable.
  232.  
  233.    See Getex03.prg
  234.  
  235.  
  236. 2. Write a get reader that invokes a code block after each key. It should
  237.    pass the block the current get object. Write a block that uses a TBrowse
  238.    object to display records matching the current variable or field. This
  239.    way, as the user enters characters, he or she automatically sees the
  240.    matching records.
  241.  
  242.    See Getex04.prg
  243.  
  244.  
  245. 3. Modify the GoToGet function so that the programmer can pass a get's
  246.    name rather than number
  247.  
  248.    See Getex05.prg
  249.  
  250.  
  251. 4. As you know, the user can leave a read just by pressing an Esc key,
  252.    regardless of whether any gets have unsatisfied valids or not. Write
  253.    a READ command that only allows the user to exit if all valid clauses
  254.    are satisfied.
  255.  
  256.    See Getex06.prg
  257.