From Clomosy Docs
(Created page with "The CloseFile procedure closes an open file. The file must be assigned and opened with Insert, Reset, or Rewrite. The file is closed and the handle is made available for further assignment to the files.<br> '''Example:'''<br> '''var''' myFile : TextFile;<br> '''begin''' // Try to open the Test.txt file for writing to AssignFile(myFile, 'Test.txt'); ReWrite(myFile);<br> // Write a couple of well known words to this file WriteLn(myFile, 'Hello'); WriteLn(m...") |
No edit summary |
||
| Line 2: | Line 2: | ||
'''Example:'''<br> | '''Example:'''<br> | ||
:'''Base Syntax''' | |||
'''var''' | '''var''' | ||
myFile : TextFile;<br> | myFile : TextFile;<br> | ||
| Line 29: | Line 30: | ||
CloseFile(myFile);<br> | CloseFile(myFile);<br> | ||
'''end;''' | '''end;''' | ||
:'''TRObject Syntax''' | |||
var | |||
myFile : TextFile; | |||
{ | |||
// Try to open the Test.txt file for writing to | |||
AssignFile(myFile, 'Test.txt'); | |||
ReWrite(myFile); | |||
// Write a couple of well known words to this file | |||
WriteLn(myFile, 'Hello'); | |||
WriteLn(myFile, 'World'); | |||
// Close the file | |||
CloseFile(myFile); | |||
// Reopen to append a final line to the file | |||
Append(myFile); | |||
// Write this final line | |||
WriteLn(myFile, 'Final line added'); | |||
// Close the file | |||
CloseFile(myFile); | |||
// Reopen the file for reading | |||
Reset(myFile); | |||
// Display the file contents | |||
while (not Eof(myFile)) | |||
ReadLn(myFile); | |||
// Close the file for the last time | |||
CloseFile(myFile); | |||
} | |||
Revision as of 13:37, 12 February 2024
The CloseFile procedure closes an open file. The file must be assigned and opened with Insert, Reset, or Rewrite. The file is closed and the handle is made available for further assignment to the files.
Example:
- Base Syntax
var myFile : TextFile;
begin // Try to open the Test.txt file for writing to AssignFile(myFile, 'Test.txt'); ReWrite(myFile);
// Write a couple of well known words to this file WriteLn(myFile, 'Hello'); WriteLn(myFile, 'World');
// Close the file CloseFile(myFile);
// Reopen to append a final line to the file Append(myFile);
// Write this final line WriteLn(myFile, 'Final line added');
// Close the file CloseFile(myFile);
// Reopen the file for reading Reset(myFile);
// Display the file contents while not Eof(myFile) do begin ReadLn(myFile); end;
// Close the file for the last time CloseFile(myFile);
end;
- TRObject Syntax
var
myFile : TextFile;
{
// Try to open the Test.txt file for writing to
AssignFile(myFile, 'Test.txt');
ReWrite(myFile);
// Write a couple of well known words to this file
WriteLn(myFile, 'Hello');
WriteLn(myFile, 'World');
// Close the file
CloseFile(myFile);
// Reopen to append a final line to the file
Append(myFile);
// Write this final line
WriteLn(myFile, 'Final line added');
// Close the file
CloseFile(myFile);
// Reopen the file for reading
Reset(myFile);
// Display the file contents
while (not Eof(myFile))
ReadLn(myFile);
// Close the file for the last time
CloseFile(myFile);
}