home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MAGAZINE / MISC / ITPMAR90.ZIP / FILELIST.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-02-22  |  1.8 KB  |  103 lines

  1. PROGRAM FileListDemo;      {FILELIST.PAS}
  2.  
  3. USES Crt, Printer;
  4.  
  5. TYPE
  6.   Action = (Input, Output);
  7.   TextObj = OBJECT
  8.     fp : text;
  9.     LineCount : integer;
  10.     EndOfFile : boolean;
  11.     CONSTRUCTOR OpenFile(FileName: string;
  12.             FileAction: Action);
  13.     PROCEDURE ReadLine(VAR TextLine: string);
  14.     PROCEDURE WriteLine(TextLine: string);
  15.     PROCEDURE PrintLine(TextLine: string);
  16.     PROCEDURE FillBlanks;
  17.     FUNCTION Done: boolean;
  18.     DESTRUCTOR CloseFile;
  19.   END;
  20.  
  21. CONSTRUCTOR TextObj.OpenFile;
  22. BEGIN
  23.   Assign(fp, FileName);
  24.   CASE FileAction of
  25.     Input:
  26.       BEGIN
  27.     LineCount := 1;
  28.     Reset(fp);
  29.     IF IOResult <> 0 THEN
  30.       BEGIN
  31.         writeln(FileName, ' not found!');
  32.         halt(1);
  33.       END;
  34.     writeln(FileName, ' opened for read...');
  35.       END;
  36.     Output:
  37.       BEGIN
  38.     Rewrite(fp);
  39.     WriteLn(FileName, ' opened for write...');
  40.       END;
  41.   END; {CASE}
  42. END;
  43.  
  44. DESTRUCTOR TextObj.CloseFile;
  45. BEGIN
  46.   Close(fp);
  47.   WriteLn('File closed...');
  48. END;
  49.  
  50. PROCEDURE TextObj.ReadLine;
  51. BEGIN
  52.   ReadLn(fp, TextLine);
  53.   EndOfFile := Eof(fp);
  54. END;
  55.  
  56. PROCEDURE TextObj.WriteLine;
  57. BEGIN
  58.   WriteLn(fp, TextLine);
  59. END;
  60.  
  61. PROCEDURE TextObj.PrintLine;
  62. BEGIN
  63.   IF not EndOfFile THEN
  64.   BEGIN
  65.     IF TextLine[1] <> '}' THEN
  66.       BEGIN
  67.     WriteLn(lst, TextLine);
  68.     Inc(LineCount);
  69.       END ELSE FillBlanks;
  70.   END;
  71. END;
  72.  
  73. PROCEDURE TextObj.FillBlanks;
  74. VAR
  75.   i : integer;
  76. BEGIN
  77.   FOR i := LineCount TO 6 DO WriteLn(lst);
  78.   LineCount := 1;
  79. END;
  80.  
  81. FUNCTION TextObj.Done;
  82. BEGIN
  83.   Done := EndOfFile;
  84. END;
  85.  
  86. VAR
  87.   InFile: TextObj;
  88.   TextLine: string;
  89.  
  90. BEGIN
  91.   ClrScr;
  92.   WITH InFile DO
  93.     BEGIN
  94.       OpenFile('DUMMY.DAT', Input);
  95.       REPEAT
  96.     ReadLine(TextLine);
  97.     PrintLine(TextLine);
  98.       UNTIL Done;
  99.       CloseFile;
  100.     END;
  101.   Write('Press Enter to quit...'); ReadLn;
  102. END.
  103.