home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / GET10.ZIP / GETDEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-11-09  |  9.7 KB  |  366 lines

  1. Program GetDemo;
  2. {
  3.   This program is intended to demonstrate the use of some GET procedures.
  4.   Refer to GETDEMO.DOC for details.
  5.  
  6.   Once you've run this and explored a little, try making some changes.
  7.   Try changing "dollars" to "SwissFrancs" and recompiling e.g. You'll
  8.   find the currency symbol will change, it's position will change, the
  9.   decimal point will change to a comma and the thousands delimiter will
  10.   change to period -- all automatically. You might change DateFormat to
  11.   European at the same time and observe the effect on subfield validation.
  12.   Note what happens when YearFormat is changed from NY to YY. Observe 
  13.   what happens to numeric field sizes when ValidationOverride is true,
  14.   when RightJustifyNumberEntry is true, etc. Have fun! P.O'N
  15. }
  16. Uses Crt, Qwik, Getvars, Get, GetFns;
  17.  
  18. Const
  19.    max_overdraft          = 999999;
  20.    minimum_avg_balance    = 500;
  21.    minimum_charge         = 2;
  22.    transaction_charge     = 0.25;
  23.  
  24. var
  25.    transactions: integer;
  26.  
  27.    children:     shortint;
  28.  
  29.    charges,
  30.    balance,
  31.    avg_balance,
  32.    overdraft:    real;
  33.  
  34.    deposit,
  35.    mortgage,
  36.    retirement,
  37.    loan,
  38.    otherAC:      boolean;
  39.  
  40.    first_name,
  41.    initial,
  42.    last_name,
  43.    street_address,
  44.    suite_no,
  45.    city, state,
  46.    zip, phone,
  47.    ssn, comment,
  48.  
  49.    testcalcstr,
  50.    password,
  51.    balance_time,
  52.    date_of_birth,
  53.    balance_date: string;
  54.  
  55.  
  56. procedure setup_test_data;
  57. {
  58.   Note: 
  59.  
  60.   Separator characters in a COMPOSITE string ('/' in date and ':' in time)
  61.   ARE part of the string. Punctuating characters in all other strings are
  62.   not part of the string if they are display only -- entered in the picture
  63.   for the string rather than the string itself. Thus, in this example, "(",
  64.   ")" and " " are not part of the telephone number string AS STORED.
  65. }
  66. begin
  67.   first_name     := 'Zorba';
  68.   initial        := 'T';
  69.   last_name      := 'Greek';
  70.   street_address := '8 Franklin Ave';
  71.   suite_no       := 'Apt 1';
  72.   city           := 'Athens';
  73.   state          := 'OH';
  74.   zip            := '457011112';
  75.   phone          := '6145946401';
  76.   ssn            := '123456789';
  77.   date_of_birth  := '01/01/60';
  78.   balance_date   := '01/01/88';
  79.   balance_time   := '12:00';
  80.   password       := '1abc';
  81.   balance        := 256.32;
  82.   avg_balance    := 123.12;
  83.   overdraft      := 2500;
  84.   transactions   := 0;
  85.  
  86.   if avg_balance >= minimum_avg_balance then
  87.     charges := 0
  88.   else charges := minimum_charge + transactions * transaction_charge;
  89.  
  90.   children       := 0;
  91.   deposit        := true;
  92.   mortgage       := false;
  93.   retirement     := true;
  94.   loan           := false;
  95.   otherAC        := false;
  96.   comment        := 'Charges applied if average balance less ' +
  97.                     'than minimum balance is: mimimum charge ' +
  98.                     'plus transactions x transaction charge.';
  99. end;
  100.  
  101.  
  102. procedure getscreen (target: integer);
  103.  
  104. Const
  105.  
  106.     lastfield = 25;   {no. of the last field on the screen}
  107.  
  108. var I,
  109.     field:            integer;
  110.     lastedit:         word;
  111.     action:           edit;
  112.  
  113.     AllFieldsDisplayOnly,
  114.     OldPaintingFields,
  115.     T,F,
  116.     HeartsContent:    boolean;
  117.     text_fieldnum:    numstring;
  118.  
  119.     cursor_attr,
  120.     dattr,
  121.     pattr:            byte;
  122.  
  123.     DisplayOnlyMap:   array[1..255] of boolean;
  124.  
  125.     previousfield,
  126.     nextfield:        array[1..255] of byte;
  127.     fieldprompt:      array[1..lastfield] of string[80];
  128.     testchar:         char;
  129.  
  130.  
  131. procedure upfield;
  132. begin
  133.   if field > 1 then dec(field)
  134.     else if FieldWrap then field := lastfield;
  135.  
  136.   if DisplayOnlyMap[field] then
  137.     upfield;
  138. end;
  139.  
  140. procedure downfield;
  141. begin
  142.   if field < lastfield then inc(field)
  143.   else if FieldWrap then field := 1;
  144.  
  145.   if DisplayOnlyMap[field] then
  146.     downfield;
  147. end;
  148.  
  149. procedure getfield(field: byte);
  150. var DisplayOnly,
  151.     SavePaint:    boolean;
  152. {
  153.   PaintingFields is switched on temporarily if a field is display only
  154. }
  155. begin
  156.     str(field,text_fieldnum);
  157.     SavePaint := PaintingFields;
  158.  
  159.     if not PaintingFields then
  160.       begin
  161.         if DisplayOnlyMap[field] then
  162.           PaintingFields := true;
  163.         info(fieldprompt[field]);
  164.       end;
  165.  
  166.     case field of
  167.       1: getstr('Last name ',3,1,last_name, 'Xx',25,1);
  168.       2: getstr('Initial ',3,38,initial,'X',1,1);
  169.       3: getstr('First name ',3,49,first_name,'Xx',20,1);
  170.       4: getstr('Street address ',5,1,street_address,'Xx',42,1);
  171.       5: getstr('Suite No. ',5,60,suite_no,'Xx',10,0);
  172.       6: getstr('City ',7,1,city,'Xx',22,1);
  173.       7: getstr('State ',7,30,state,'XX',2,3);
  174.       8: getstr('Zip ',7,40,zip,'99999+9999',9,3);
  175.       9: getstr('Tel. ',7,56,phone,'(999)B999-9999',10,2);
  176.      10: getdatestr('Date of birth ',9,1,date_of_birth,3);
  177.      11: getshortint('No. of children ',9,27, 0,99, pattr,dattr,children,'0');
  178.      12: getstr('Social Security No. ',9,47,ssn,'999-99-9999',9,3);
  179.  
  180.      13:  begin
  181.             PasswordField := T;
  182.             getstr('Password ',11,1,password,'9x',4,0); {9x: documentation}
  183.             PasswordField := F;
  184.           end;
  185.  
  186.      14:  getreal('Account balance ',11,16,
  187.                      -abs(overdraft),99999.99,dollars,pattr,dattr,balance,'0');
  188.  
  189.      15: getdatestr('on ',11,49,balance_date,2);
  190.      16: gettimestr('at ',11,64,balance_time,2);
  191.  
  192.      17: getreal('Overdraft limit ',
  193.                   13,1,0,max_overdraft,dollars,pattr,dattr,overdraft,'0');
  194.  
  195.      18: getreal('Average balance this month ',13,33,
  196.                  -abs(overdraft),999999.99,dollars,pattr,dattr,avg_balance,'');
  197.  
  198.      19: getinteger('Transactions this month ',15,1,
  199.                     0,9999,pattr,dattr,transactions,'0');
  200.  
  201.      20: getbool
  202.            ('Accounts: Deposit    ',17,1,deposit);
  203.      21: getbool('Mortgage   ',18,11,mortgage);
  204.      22: getbool('Retirement ',19,11,retirement);
  205.      23: getbool('Loan       ',20,11,loan);
  206.      24: getbool('Other      ',21,11,otherAC);
  207.  
  208.      25: getstr('Comment ',18,30,comment,
  209.                 'x@'+ #39 + '\N@' + #40 + '\N@' + #40, {picture}
  210.                 120,0);
  211.     end; {case}
  212.  
  213. {
  214.   Calculated field, depends on fields 18 and 19:
  215. }
  216.  
  217.   if field in [18,19] then
  218.     begin
  219.       PaintingFields := true;
  220.       if avg_balance >= minimum_avg_balance then
  221.         charges := 0
  222.       else charges := minimum_charge + transactions * transaction_charge;
  223.       getreal('Charges this month    ',15,33,
  224.                0,0,dollars,pattr,dattr,charges,'0');
  225.     end;
  226.  
  227.  
  228.   PaintingFields := SavePaint;
  229. end;
  230.  
  231. procedure get_input;
  232. var exit_requested: boolean;
  233. begin
  234.   exit_requested := false;
  235.   getfield(field);
  236.   action := get_edit(command); {what was the last command?}
  237.  
  238.   case action of {amend this list as required}
  239.  
  240.     help:          begin
  241.                      altwrite(1,1,AttrNM,AttrBO,'~',
  242.                      '~Help~ on field ~' + text_fieldnum +
  243.                      '~? You must be joking~!~ ' +
  244.                      'Press ~Esc~ to exit');
  245.                    end;
  246.  
  247.     escapefrom:    HeartsContent := true;
  248.     tabback,
  249.     leftchar:      field := previousfield[field];
  250.     tabover,
  251.     rightchar:     field := nextfield[field];
  252.     goto_top:      field := 1;
  253.     goto_bottom:   field := lastfield;
  254.     upchar:        upfield;
  255.  
  256.     post_letter,   {will exit if AutoTab and field is complete}
  257.     enter_default,
  258.     carriage_return,
  259.     downchar:      downfield;
  260.     exit_screen:   exit_requested := true;
  261.   end; {case}
  262.  
  263.   if (field > lastfield) or exit_requested then
  264.     begin
  265.       getresponse('OK so far ~Y~/~N~? ',CharacterSet[YesAndNo].CharSet,
  266.                   24,1,false,testchar,'Y');
  267.       HeartsContent := upcase(testchar) = 'Y';
  268.       if not HeartsContent and (field > lastfield) then
  269.         field := lastfield;
  270.     end;
  271. end;
  272.  
  273.  
  274. begin {getscreen}
  275.  
  276.   fillchar(DisplayOnlyMap,sizeof(DisplayOnlyMap),0);
  277.  
  278.   pattr       := Default_pattr;       {field prompt attribute}
  279.   dattr       := Default_dattr;       {field data attribute}
  280.   cursor_attr := Default_cursor_attr; {cursor attribute in strings}
  281.  
  282.   field := 1;
  283.   T := true;
  284.   F := not T;
  285.  
  286.   if (target < 1) or (target > lastfield) then
  287.     target := 1;
  288. {
  289.   q&d method of determining horizontal neighbouring fields
  290. }
  291.   for I := 1 to lastfield do
  292.     begin
  293.      nextfield[I] := succ(I);
  294.      previousfield[I] := pred(I);
  295.     end;
  296.   nextfield[lastfield] := 1;
  297.   previousfield[1] := lastfield;
  298. {
  299.   initialise field prompts
  300. }
  301.   for I := 1 to lastfield do
  302.     begin
  303.       str(I,text_fieldnum);;
  304.       fieldprompt[I] := 'This is field no ' + text_fieldnum +
  305.                         ' Press ~Esc~ to exit';
  306.     end;
  307.  
  308.  
  309.   DisplayOnlyMap[18]   := true;
  310.   AllFieldsDisplayOnly := false; {see upfield/downfield recursion}
  311.  
  312.  
  313.   {1st paint screen}
  314.  
  315.   ClrScr;
  316.   PaintingFields := true;
  317.  
  318.   for field := 1 to lastfield do
  319.     getfield(field);
  320.  
  321.   PaintingFields := false;
  322.   HeartsContent  := false;
  323.   field          := target;
  324.   cp             := 1;      {cursor position in string}
  325.  
  326.   {now look for input}
  327.  
  328.   if not AllFieldsDisplayOnly then
  329.     repeat
  330.       get_input
  331.     until HeartsContent;
  332.  
  333.   SetCursor (CursorOn or CursorInitial);
  334. end;
  335.  
  336.  
  337. procedure setup_global_variables;
  338. begin
  339.   DateFormat              := American;
  340.   YearFormat              := NY;
  341.   ValidationOverride      := not true;
  342.   RightJustifyNumberEntry := not true;
  343.   StringFieldWrap         := true;
  344.   FieldWrap               := true;
  345.   tabsize                 := 0;
  346. end;
  347.  
  348.  
  349. procedure finish_up;
  350. {
  351.   Reset video mode to what we started with (e.g. CO40)
  352. }
  353. begin
  354.   clrscr;
  355.   if QVideoMode <> LastVideoMode then
  356.     TextMode (LastVideoMode + hi(LastMode));
  357. end;
  358.  
  359.  
  360. begin
  361.   setup_global_variables;
  362.   setup_test_data;
  363.   getscreen(1);
  364.   finish_up;
  365. end.
  366.