home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / findrepl.swg / 0009_NEXTCHAR.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  56 lines

  1. {
  2. Duncan Murdoch
  3.  
  4. >var
  5. >  TextFile: Text;
  6. >  NextChar: Char;
  7. >...
  8. >begin
  9. >...
  10. >  with TextRec(TextFile) do  NextChar:= Buffer[BufPos];
  11.  
  12. Careful!  This is unreliable, because the Buffer could be empty.  You should
  13. check that there's something there, and fill it if not.
  14.  
  15. Here's my NextChar routine.  BTW, I don't like the DOS unit's declaration of
  16. TextRec, so I wrote my own.
  17. }
  18.  
  19. type
  20.   IOFunc = function(var Source:text): Integer;
  21.   TTextBuf = array[0..127] of char;
  22.   PTextBuf = ^TTextBuf;
  23.   TextRec = record
  24.     Handle: Word;
  25.     Mode: Word;
  26.     BufSize: Word;
  27.     Private: Word;
  28.     BufPos: Word;
  29.     BufEnd: Word;
  30.     BufPtr: PTextBuf;
  31.     OpenFunc: IOFunc;
  32.     InOutFunc: IOFunc;
  33.     FlushFunc: IOFunc;
  34.     CloseFunc: IOFunc;
  35.     UserData: array[1..16] of Byte;
  36.     Name: array[0..79] of Char;
  37.     Buffer: TTextBuf;
  38.   end;
  39.  
  40. function NextChar(var Source: text):char;
  41. begin
  42.   NextChar := chr(0);        { This is the default value in case of
  43.                                error }
  44.   with TextRec(Source) do
  45.   begin
  46.     if BufPos >= BufEnd then
  47.       { Buffer empty; need to fill it }
  48.       InOutRes := InOutFunc(Source);   { This sets the System error
  49.                                          variable InOutRes; other than
  50.                                          that, it ignores errors. }
  51.     NextChar := BufPtr^[BufPos]      { A test here of whether a
  52.                                        a character was available
  53.                                        would be a good idea }
  54.   end;
  55. end;
  56.