From Clomosy Docs
No edit summary |
ClomosyAdmin (talk | contribs) No edit summary |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert"> | |||
procedure CloseFile(var FileHandle TextFile); | |||
</div> | |||
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> | 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> | ||
<b>Example</b><br> | |||
<pre> | |||
var | |||
myFile : TextFile; | myFile : TextFile; | ||
{ | |||
// Try to open the Test.txt file for writing to | // Try to open the Test.txt file for writing to | ||
AssignFile(myFile, 'Test.txt'); | AssignFile(myFile, 'Test.txt'); | ||
ReWrite(myFile); | ReWrite(myFile); | ||
// Write a couple of well known words to this file | // Write a couple of well known words to this file | ||
WriteLn(myFile, 'Hello'); | WriteLn(myFile, 'Hello'); | ||
WriteLn(myFile, 'World'); | WriteLn(myFile, 'World'); | ||
// Close the file | // Close the file | ||
CloseFile(myFile); | |||
// Reopen to append a final line to the file | // Reopen to append a final line to the file | ||
Append(myFile); | Append(myFile); | ||
// Write this final line | // Write this final line | ||
WriteLn(myFile, 'Final line added'); | WriteLn(myFile, 'Final line added'); | ||
// Close the file | // Close the file | ||
CloseFile(myFile); | CloseFile(myFile); | ||
// Reopen the file for reading | // Reopen the file for reading | ||
Reset(myFile); | Reset(myFile); | ||
// Display the file contents | // Display the file contents | ||
while not Eof(myFile) | while (not Eof(myFile)) | ||
ReadLn(myFile); | ReadLn(myFile); | ||
// Close the file for the last time | // Close the file for the last time | ||
CloseFile(myFile);< | CloseFile(myFile); | ||
} | |||
</pre> | |||
<h2> See Also </h2> | |||
* [[File_Handling | File Handling]] | |||
{{#seo:|title=CloseFile Using in Clomosy - Clomosy Docs}} | |||
{{#seo:|description=Learn about CloseFile on Clomosy. Understand how to properly handle file closing operations to improve your application's performance.}} | |||
Latest revision as of 13:28, 24 December 2024
procedure CloseFile(var FileHandle TextFile);
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
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);
}