home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 18 / CD_ASCQ_18_111294_W.iso / dos / prg / pas / theprn25 / demo_prn.pas < prev    next >
Pascal/Delphi Source File  |  1994-07-24  |  4KB  |  156 lines

  1. (*=========================================================================
  2.  
  3.     Name:       Demo_Prn.Pas   Copyright 1992-94, Rob W. Smetana
  4.                 Support file for The Printer (tm).
  5.  
  6. Requires:       PRINTER.CFG.
  7.  
  8.                 This program displays the contents of Printer.Cfg.
  9.  
  10.                 So BEFORE you run this, you MUST run Printer.Exe,
  11.                 select a printer, then press F2 to SAVE Printer.Cfg.
  12.  
  13.  
  14.  Purpose:       * Demonstrate reading printer code records.
  15.  
  16.                 * Show how one might display printer codes.
  17.  
  18.                   Something like this might be used inside a
  19.                   program to show users which codes are
  20.                   available (ie., not blank) and perhaps what
  21.                   they should do to invoke each option.
  22.  
  23.     NOTE:       Some printer codes may contain control codes which
  24.                 will screw up the display.  Try a different printer.
  25.                 And in your own programs you might want to use an ASM
  26.                 "quickprint" routine to overcome this problem.
  27.  
  28. =========================================================================*)
  29.  
  30. Program Demo_Prn;
  31.  
  32. Uses DOS,CRT;
  33.  
  34. { ...include two TYPES useful for reading printer codes. }
  35.  
  36. {$I The_Prn.Pas}
  37.  
  38. {...NOTE:  Although we loaded some TYPEs, we won't use them!  For what     }
  39. {   we're about to do, it's easier to read codes in simple 14-byte chunks. }
  40.  
  41. Var
  42.  
  43.   F     : File;
  44.   Headr : Array[1..44] of Char;
  45.   Labels: Array[1..980] of Char;
  46.   Codes : Array[1..980] of Char;
  47.  
  48.   Cfg_File: String;
  49.  
  50.   Ch : Char;
  51.   Temp, N, Offset : Integer;
  52.   BytesRead : Word;
  53.   Row, Col : Byte;
  54.  
  55. {=========================================================================}
  56. Procedure PrintHeader;                  { print Manufacturer, model, etc. }
  57. {=========================================================================}
  58.   Begin
  59.   TextAttr := 27; ClrScr;
  60.   For N := 0 to 43 Do                   { print our 44-byte header }
  61.      Begin
  62.         Case N of
  63.           0:  Write ( '  Manufacturer: ');
  64.           17: Write ( ' Model: ');
  65.           31: Write ( ' Emulation: ');
  66.         End;
  67.         Write(Headr [N]);
  68.      End;
  69.    TextAttr := 26;
  70.    End;
  71.  
  72. {=========================================================================}
  73. Begin
  74. {=========================================================================}
  75.  
  76.   Cfg_File := 'Printer.Cfg';
  77.  
  78.   {$I-}
  79.  
  80.   ClrScr;
  81.  
  82.   Assign(F, Cfg_File);
  83.   Reset(F, 1);
  84.  
  85.   If IOResult <> 0 then
  86.      Begin
  87.         Write('Error:  ',Cfg_File, ' was not found! ');
  88.         Close(F);
  89.         Halt;
  90.      End;
  91.  
  92.   { read the header, the labels, the header again and the printer codes }
  93.   BlockRead (F, Headr, SizeOf(Headr), BytesRead);
  94.   BlockRead (F, Labels, SizeOf(Labels), BytesRead);
  95.   BlockRead (F, Headr, SizeOf(Headr), BytesRead);
  96.   BlockRead (F, Codes, SizeOf(Codes), BytesRead);
  97.  
  98.   If IOResult <> 0 then
  99.      Begin
  100.         Write('Error reading: ',Cfg_File,'');
  101.         Close(F);
  102.         Halt;
  103.      End;
  104.  
  105.   Close(F);
  106.  
  107.   PrintHeader;
  108.  
  109.   { Now parse our two 980-byte buffers and print Labels:Codes }
  110.  
  111.   Offset :=1 ;Row := 3; Col := 3;
  112.  
  113.   { Display our 70, 14-byte labels and printer codes }
  114.  
  115.   For Temp := 1 to 70 Do
  116.  
  117.     Begin
  118.  
  119.        GotoXY(Col, Row);
  120.        { Print the labels }
  121.        For N := 1 to 14 Do
  122.            Write(Labels[Offset+N-1]);
  123.  
  124.        Write('    ');
  125.  
  126.        { and now the codes }
  127.        For N := 1 to 14 Do
  128.            Write(Codes[Offset+N-1]);
  129.  
  130.        { move to the next }
  131.        Offset := Offset + 14;
  132.  
  133.        { there are more codes than will fit on a screen, so pause }
  134.  
  135.        If (Temp = 42) then
  136.           Begin
  137.             GotoXY(15, 25); Write ('There''s more.   Press <SPACE> to continue . . .');
  138.             Ch:=ReadKey;
  139.             If Ch = #27 then Halt;
  140.             PrintHeader;
  141.             Row :=2; Col := 3;
  142.           End;
  143.  
  144.        Inc(Row);
  145.  
  146.        If (Row > 23) then
  147.           Begin
  148.             Row :=3; Col := 40;
  149.           End;
  150.     End;
  151.  
  152.     GotoXY(15, 25); Write ('That''s all.     Press <SPACE> to continue . . .');
  153.     Ch:=ReadKey;
  154.  
  155. End.
  156.