delphiioconsolepascal

Reset Input back to console window?


Is there any way in Free Pascal/Delphi to reset the standard Input file back to console window after it was assigned to a 'real file' temporarily?

     AssignFile(Input, 'stdin.txt');
     ...
     CloseFile(Input);
     // ??
     ReadLn(x); // I/O error

Solution

  • Per Delphi's documentation:

    https://docwiki.embarcadero.com/Libraries/en/System.AssignFile

    When the FileName parameter is empty, AssignFile associates F with the standard input or standard output file. If assigned an empty name, after a call to Reset (F), F refers to the standard input file, and after a call to Rewrite (F), F refers to the standard output file.