home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / Pascal / AIM.ZIP / AIMDEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-06-29  |  14.0 KB  |  474 lines

  1.  
  2. {D+}                    {debug information}
  3. {T-}                    {create .TPM file for debugging}
  4. {F-}                    {automatically force far calls}
  5. {V-}                    {var string checking}
  6. {L+}                    {link buffer in memory}
  7. {$R-}                   {range checking}
  8. {$B+}                   {boolean complete evaluation}
  9. {$S+}                   {stack checking}
  10. {$I+}                   {I/O checking}
  11. {$N-}                   {numeric coprocessor}
  12. {$M 65500,0,4000}       {memory sizes}
  13.  
  14. {***************************************************************************}
  15. {*                                                                         *}
  16. {*      AIMDEMO.PAS         Copyright - Matt Goodrich                      *}
  17. {*                              Jun 29, 1991                               *}
  18. {*                                                                         *}
  19. {*   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   *}
  20. {*                                                                         *}
  21. {*      Maintenance History :                                              *}
  22. {*                                                                         *}
  23. {*  1.A  MG  6/29/91 - Initial Keyin.                                      *}
  24. {*                                                                         *}
  25. {***************************************************************************}
  26.  
  27. PROGRAM AIMDEMO;
  28.  
  29. USES
  30.  
  31.   CRT, MISCSTUF, AIMUNIT;
  32.  
  33. CONST
  34.   Version           = '1.A';    {version number of program}
  35.  
  36.   EOF_Mark          = CHR (26);
  37.   CarrRet           = CHR (13);
  38.   LineFeed          = CHR (10);
  39.  
  40. VAR
  41.   CharsRead    : INTEGER;
  42.   CharsWrit    : INTEGER;
  43.   DataFile     : FILE;
  44.   Demo         : AimVars;
  45.   I            : INTEGER;
  46.   MyKeyedChar  : INTEGER;
  47.   NewField     : STRING [ 6];
  48.   ReadBuffer   : ARRAY [1..200] OF CHAR;
  49.  
  50.   TempInteger  : INTEGER;
  51.   TempString03 : STRING [ 3];
  52.   TempString70 : STRING [70];
  53.   TempStringA  : STRING [31];
  54.   TempStringB  : STRING [ 6];
  55.   TempStringC  : STRING [33];
  56.  
  57.   TextFile     : TEXT;
  58.   TextString   : ARRAY [1..5] OF STRING [70];
  59.  
  60.  
  61.  
  62. {***************************************************************************}
  63.  
  64. PROCEDURE Anything;
  65.  
  66. BEGIN
  67.  
  68. END;
  69.  
  70. {***************************************************************************}
  71.  
  72. PROCEDURE HaltDemo (DosErrorLevel : INTEGER);
  73.  
  74. BEGIN
  75.  
  76.   GOTOXY (78, 23);
  77.   Cursor_On;
  78.   HALT (DosErrorLevel);
  79.  
  80. END;
  81.  
  82. {***************************************************************************}
  83.  
  84. PROCEDURE PressAnyKeyKeyin;
  85.  
  86. BEGIN
  87.   Disp_String ('Press any key to continue...', 1, 23, Normal_Video);
  88.   Keyin_Char (MyKeyedChar);
  89.   IF MyKeyedChar = ESC_Key
  90.      THEN HaltDemo (1);
  91.  
  92. END;
  93.  
  94. {***************************************************************************}
  95.  
  96. PROCEDURE ClearSomeOfScreen;
  97.  
  98. BEGIN
  99.    WINDOW (1, 10, 80, 25);
  100.    CLRSCR;
  101.    WINDOW (1,  1, 80, 25);
  102. END;
  103.  
  104. {***************************************************************************}
  105.  
  106. BEGIN    {Main Procedure AimDemo}
  107.  
  108.   Ins_Mode := Yes;
  109.  
  110.   RANDOMIZE;
  111.  
  112.   CLRSCR;
  113.  
  114.   Disp_String ('Progam ',  1,  1, Normal_Video);
  115.   Disp_String ('Version: ' + Version,  60,  1, Normal_Video);
  116.  
  117.  
  118.  
  119.  
  120.  
  121.   Disp_String ('This program is a demo of AIM showing how it might be used',
  122.                       10,  6, Normal_Video);
  123.   Disp_String ('and how to code it.  Since the point of this demo is the',
  124.                       10,  7, Normal_Video);
  125.   Disp_String ('source code, I opted for keeping it as simple as possible.',
  126.                       10,  8, Normal_Video);
  127.   Disp_String ('It may seem a little crude.', 10,  9, Normal_Video);
  128.  
  129.   Disp_String ('See the file "AIMDEX.DOC" for more information.',
  130.                       10, 11, Normal_Video);
  131.  
  132.   PressAnyKeyKeyin;
  133.  
  134.  {**************************************************************************}
  135.  
  136.   CLRSCR;
  137.  
  138.   Disp_String ('Here''s the way the datafile looks:', 10, 1, Normal_Video);
  139.   Disp_String ('----------------------------------------------------------' +
  140.                       '------------', 1, 2, Bold_Video);
  141.   Disp_String ('----------------------------------------------------------' +
  142.                       '------------', 1, 8, Bold_Video);
  143.  
  144.  
  145.   TextString [1] := '11111 JANE DOE           TIPPLE CORP                ' +
  146.                  'NEW YORK          ';
  147.   TextString [2] := '22222 BOB SMITH          WINGS & FEATHERS, INC      ' +
  148.                  'INDIANA           ';
  149.   TextString [3] := '33333 SAM JONES          LEMON TRUCKS               ' +
  150.                  'NEW YORK          ';
  151.   TextString [4] := '44444 TOM JONES          ACME RANCH                 ' +
  152.                  'MONTANA           ';
  153.   TextString [5] := '55555 BUFFY SIMMONS      FEATHERBEDS, LTD           ' +
  154.                  'FLORIDA           ';
  155.  
  156.  
  157.   ASSIGN (TextFile, 'AIMDEMO.TXT');
  158.   REWRITE (TextFile);
  159.  
  160.   FOR I:= 1 TO 5 DO
  161.     BEGIN
  162.        WRITELN (TextFile, TextString [I]);
  163.        Disp_String (TextString [I], 1, I+2, Normal_Video);
  164.     END;
  165.  
  166.   WRITE (TextFile, EOF_Mark);
  167.   CLOSE (TextFile);
  168.  
  169.  
  170.   { -- Technically speaking, I should also rebuild the aimdex at this point,  }
  171.   { -- but for the purposes of this crude demo program, I don't actually need }
  172.   { -- to.  The old aimdex is still functional.                               }
  173.  
  174.  {**************************************************************************}
  175.  {**************************************************************************}
  176.  
  177.   Demo.AimFileName := 'AIMDEMO.AIM';
  178.   Aim_OpenFile (Demo);
  179.  
  180.   IF Demo.FileOpen = 'A'
  181.     THEN BEGIN
  182.            Disp_String ('Crash!  I could not open AIMDEMO.AIM.', 1, 15,
  183.                                Bold_Video);
  184.            HaltDemo (1);
  185.          END
  186.   ELSE IF Demo.FileOpen = 'D'
  187.     THEN BEGIN
  188.            Disp_String ('Crash!  I could not open AIMDEMO.TXT.', 1, 15,
  189.                                Bold_Video);
  190.            HaltDemo (1);
  191.          END
  192.   ;
  193.  
  194.   ASSIGN (DataFile, Demo.DataFileName);
  195.   RESET (DataFile, 1);
  196.  
  197.  {**************************************************************************}
  198.  {**************************************************************************}
  199.  
  200.   Disp_String ('Let''s start out by saying we have the above datafile ' +
  201.                '(AIMDEMO.TXT) and its', 1, 10, Normal_Video);
  202.   Disp_String ('aimdex file (AIMDEMO.AIM), which was created by doing:',
  203.                1, 11, Normal_Video);
  204.  
  205.   Disp_String ('AIMDEXP AIMDEMO.TXT AIMDEMO.AIM  7-24,26-51,53-68',
  206.                5, 13, Bold_Video);
  207.  
  208.   PressAnyKeyKeyin;
  209.   ClearSomeOfScreen;
  210.  
  211.  {**************************************************************************}
  212.  
  213.   Disp_String ('Now I''ll do a Read for "Feath" in the 2nd aim field:',
  214.                1, 10, Normal_Video);
  215.   PressAnyKeyKeyin;
  216.  
  217.  
  218.   Demo.AimKey [1] := '2Feath';
  219.   Demo.AimKey [2] := '';
  220.   Demo.AimKey [3] := '';
  221.   Aim_Read (Demo);
  222.  
  223.   IF Demo.Found = Yes
  224.    THEN BEGIN
  225.           SEEK (DataFile, Demo.SeekPosData);
  226.           BLOCKREAD (DataFile, ReadBuffer, 72, CharsRead);
  227.           TempString70 := '';
  228.           FOR I:= 1 TO 70 DO TempString70 := TempString70 + ReadBuffer [I];
  229.  
  230.           Disp_String ('OK. I found:', 1, 12, Normal_Video);
  231.           Disp_String (TempString70, 1, 14, Reverse_Video);
  232.         END;
  233.  
  234.   PressAnyKeyKeyin;
  235.  
  236.  {**************************************************************************}
  237.  
  238.   Disp_String ('Now I''ll do a ReadKG:', 1, 16, Normal_Video);
  239.  
  240.   PressAnyKeyKeyin;
  241.  
  242.   Aim_ReadKG (Demo);
  243.   IF Demo.Found = Yes
  244.    THEN BEGIN
  245.           SEEK (DataFile, Demo.SeekPosData);
  246.           BLOCKREAD (DataFile, ReadBuffer, 72, CharsRead);
  247.           TempString70 := '';
  248.           FOR I:= 1 TO 70 DO TempString70 := TempString70 + ReadBuffer [I];
  249.  
  250.           Disp_String ('OK. I found:', 1, 18, Normal_Video);
  251.           Disp_String (TempString70, 1, 20, Reverse_Video);
  252.         END;
  253.  
  254.   PressAnyKeyKeyin;
  255.  
  256.  {**************************************************************************}
  257.  
  258.   ClearSomeOfScreen;
  259.  
  260.  
  261.   Disp_String ('Let''s do one more ReadKG:', 1, 10, Normal_Video);
  262.  
  263.   PressAnyKeyKeyin;
  264.  
  265.   Aim_ReadKG (Demo);
  266.   IF Demo.Found = No
  267.    THEN BEGIN
  268.           Disp_String ('This time I didn''t find anything.', 1, 12,
  269.                            Normal_Video);
  270.           Disp_String ('(we''re at the end of the file.)', 1, 13, Normal_Video);
  271.         END;
  272.  
  273.   PressAnyKeyKeyin;
  274.  
  275.  {**************************************************************************}
  276.  
  277.   Disp_String ('Now let''s do a ReadKP:', 1, 16, Normal_Video);
  278.  
  279.   PressAnyKeyKeyin;
  280.  
  281.   Aim_ReadKP (Demo);
  282.   IF Demo.Found = Yes
  283.    THEN BEGIN
  284.           SEEK (DataFile, Demo.SeekPosData);
  285.           BLOCKREAD (DataFile, ReadBuffer, 72, CharsRead);
  286.           TempString70 := '';
  287.           FOR I:= 1 TO 70 DO TempString70 := TempString70 + ReadBuffer [I];
  288.  
  289.           Disp_String ('OK. I found:', 1, 18, Normal_Video);
  290.           Disp_String (TempString70, 1, 20, Reverse_Video);
  291.         END;
  292.  
  293.   PressAnyKeyKeyin;
  294.  
  295.  
  296.  {**************************************************************************}
  297.  
  298.   ClearSomeOfScreen;
  299.  
  300.  
  301.   Disp_String ('This time I''m going to search for "Jones" in the 1st aim',
  302.                 1, 10, Normal_Video);
  303.   Disp_String ('field and "TANA" in the 3rd aim field:', 1, 11, Normal_Video);
  304.   PressAnyKeyKeyin;
  305.  
  306.   Demo.AimKey [1] := '1Jones';
  307.   Demo.AimKey [2] := '3tana';
  308.   Demo.AimKey [3] := '';
  309.   Aim_Read (Demo);
  310.  
  311.   IF Demo.Found = Yes
  312.    THEN BEGIN
  313.           SEEK (DataFile, Demo.SeekPosData);
  314.           BLOCKREAD (DataFile, ReadBuffer, 72, CharsRead);
  315.           TempString70 := '';
  316.           FOR I:= 1 TO 70 DO TempString70 := TempString70 + ReadBuffer [I];
  317.  
  318.           Disp_String ('OK. I found:', 1, 13, Normal_Video);
  319.           Disp_String (TempString70, 1, 15, Reverse_Video);
  320.         END;
  321.  
  322.   PressAnyKeyKeyin;
  323.  
  324.  {**************************************************************************}
  325.  
  326.   ClearSomeOfScreen;
  327.  
  328.  
  329.   Disp_String ('OK.  Now let''s change a record.',
  330.                 1, 10, Normal_Video);
  331.  
  332.   Disp_String ('First search for "SAM JONES" in the 1st aim field:',
  333.                 1, 12, Normal_Video);
  334.   PressAnyKeyKeyin;
  335.  
  336.   Demo.AimKey [1] := '1Sam Jones';
  337.   Demo.AimKey [2] := '';
  338.   Demo.AimKey [3] := '';
  339.   Aim_Read (Demo);
  340.  
  341.   IF Demo.Found = Yes
  342.    THEN BEGIN
  343.           SEEK (DataFile, Demo.SeekPosData);
  344.           BLOCKREAD (DataFile, ReadBuffer, 72, CharsRead);
  345.           TempStringA := '';
  346.           TempStringB := '';
  347.           TempStringC := '';
  348.           FOR I:=  1 TO 31 DO TempStringA := TempStringA + ReadBuffer [I];
  349.           FOR I:= 32 TO 37 DO TempStringB := TempStringB + ReadBuffer [I];
  350.           FOR I:= 38 TO 70 DO TempStringC := TempStringC + ReadBuffer [I];
  351.  
  352.           Disp_String ('OK. I found:', 1, 14, Normal_Video);
  353.           Disp_String (TempStringA + TempStringB + TempStringC, 1, 16,
  354.                                        Reverse_Video);
  355.         END;
  356.  
  357.   PressAnyKeyKeyin;
  358.  
  359.  {**************************************************************************}
  360.  
  361.   NewField := 'CARS  ';
  362.  
  363.   Disp_String ('Let''s change the string "TRUCKS" to "' + NewField + '":',
  364.                1, 18, Normal_Video);
  365.  
  366.   PressAnyKeyKeyin;
  367.  
  368.  
  369.   FOR I:=  1 TO 31 DO ReadBuffer [I] := TempStringA [I];
  370.   FOR I:= 32 TO 37 DO ReadBuffer [I] := NewField [I-31];
  371.   FOR I:= 38 TO 70 DO ReadBuffer [I] := TempStringC [I-37];
  372.  
  373.   SEEK (DataFile, Demo.SeekPosData);
  374.   BLOCKWRITE (DataFile, ReadBuffer, 72, CharsWrit);
  375.  
  376.   Aim_InsertKey (Demo);
  377.  
  378.   Disp_String (NewField, 32, 5, Normal_Video);
  379.   Disp_String ('POOF!   I just changed it.', 1, 20, Bold_Video);
  380.  
  381.   PressAnyKeyKeyin;
  382.  
  383.  {**************************************************************************}
  384.  
  385.   ClearSomeOfScreen;
  386.  
  387.  
  388.   Disp_String ('Now when I read the "SAM JONES" record, I get:',
  389.                 1, 10, Normal_Video);
  390.  
  391.   PressAnyKeyKeyin;
  392.  
  393.   Demo.AimKey [1] := '1Sam Jones';
  394.   Demo.AimKey [2] := '';
  395.   Demo.AimKey [3] := '';
  396.   Aim_Read (Demo);
  397.  
  398.   IF Demo.Found = Yes
  399.    THEN BEGIN
  400.           SEEK (DataFile, Demo.SeekPosData);
  401.           BLOCKREAD (DataFile, ReadBuffer, 72, CharsRead);
  402.           TempString70 := '';
  403.           FOR I:=  1 TO 70 DO TempString70 := TempString70 + ReadBuffer [I];
  404.  
  405.           Disp_String (TempString70, 1, 12, Reverse_Video);
  406.         END;
  407.  
  408.   PressAnyKeyKeyin;
  409.  
  410.  {**************************************************************************}
  411.  
  412.   ClearSomeOfScreen;
  413.  
  414.   Disp_String ('Now let''s add a new record.', 1, 11, Normal_Video);
  415.  
  416.   PressAnyKeyKeyin;
  417.  
  418.  
  419.   TempString70 := '66666 GEORGE SMITH       ACME COWS                  ' +
  420.                  'WYOMING           ';
  421.  
  422.   FOR I:=  1 TO 70 DO ReadBuffer [I] := TempString70 [I];
  423.   ReadBuffer [71] := CarrRet;
  424.   ReadBuffer [72] := LineFeed;
  425.  
  426.   Demo.SeekPosData := FILESIZE (DataFile) - 1;  {overwrite EOF}
  427.   SEEK (DataFile, Demo.SeekPosData);
  428.   BLOCKWRITE (DataFile, ReadBuffer, 72, CharsWrit);
  429.  
  430.   ReadBuffer [1] := EOF_Mark;
  431.   BLOCKWRITE (DataFile, ReadBuffer,  1, CharsWrit);
  432.  
  433.  
  434.  
  435.   { -- This flushs the write buffer.  You may want to take this code out  }
  436.   { -- in order to improve performance slightly.  See AIMDEX.DOC for more }
  437.   { -- details.                                                           }
  438.   CLOSE (DataFile);
  439.   RESET (DataFile, 1);
  440.  
  441.  
  442.  
  443.   Aim_InsertKey (Demo);
  444.  
  445.  
  446.   Disp_String (TempString70, 1, 8, Normal_Video);
  447.  
  448.  
  449.   Disp_String ('----------------------------------------------------------' +
  450.                       '------------', 1, 9, Bold_Video);
  451.  
  452.   Disp_String ('POOF!   I just added a record.', 1, 13, Bold_Video);
  453.  
  454.   PressAnyKeyKeyin;
  455.  
  456.  {**************************************************************************}
  457.  
  458.   ClearSomeOfScreen;
  459.  
  460.   Disp_String ('That''s it for this demo!', 1, 16, Bold_Video);
  461.  
  462.   PressAnyKeyKeyin;
  463.  
  464.  
  465.  
  466.  
  467.   HaltDemo (0);
  468.  
  469. END.
  470.  
  471. {***************************************************************************}
  472. {***                          End of AIMDEMO.PAS                         ***}
  473. {***************************************************************************}
  474.