From Clomosy Docs
(Created page with "The AssignFile procedure assigns a value for a FileName in preparation for reading or writing to that file.<br> Version 1<br> Takes a text file variable type as the handle. The file is treated as a textfile when opened. If the file name is an empty string, then file access is made to the console standard input and output streams.<br> Version 2<br> Takes a binary file variable type as the handle. The file is treated as a binary file.<br> In both cases, when the f...") |
ClomosyAdmin (talk | contribs) No edit summary |
||
| (5 intermediate revisions by one other user 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 AssignFile(var FileHandle TextFile; const FileName string); | |||
</div> | |||
It is used to associate a file variable with a file name, enabling the program to interact with a specific file.<br> | |||
The `AssignFile` function creates a file variable and associates it with the specified file name.<br> | |||
The function takes two parameters: the first parameter is the variable corresponding to the created `TextFile` object, and the second parameter is the name of the file to be created.<br> | |||
In both cases, when the file is opened by Append, Reset or ReWrite, it is assumed to be in the current directory. | In both cases, when the file is opened by Append, Reset or ReWrite, it is assumed to be in the current directory. | ||
'' | <div class="alert alert-warning" role="alert" data-bs-theme="light"> | ||
In the Clomosy Learn application, the file path should be specified as follows for saving files within the project directory.<br> | |||
myFile : TextFile; | AssignFile(FileHandle, <b>Clomosy.AppFilesPath</b>+'TaskList.txt'); | ||
</div> | |||
<b>Example</b><br> | |||
<pre> | |||
var | |||
myFile : TextFile; | |||
{ | |||
// Try to open the Test.txt file for writing to | // Try to open the Test.txt file for writing to | ||
AssignFile(myFile, Clomosy.AppFilesPath+'TaskList.txt'); | |||
ReWrite(myFile); | ReWrite(myFile); | ||
ShowMessage('The file is added to the directory where the exe is located.'); | |||
// Write a couple of well known words to this file | // Write a couple of well known words to this file | ||
WriteLn(myFile, ' | WriteLn(myFile, 'Task 1'); | ||
WriteLn(myFile, ' | WriteLn(myFile, 'Task 2'); | ||
ShowMessage('Lines have been added to the file.'); | |||
// Close the file | // Close the file | ||
CloseFile(myFile);< | CloseFile(myFile); | ||
} | |||
</pre> | |||
<b>Output:</b><br> | |||
After the file has been saved, it appears as follows.<br> | |||
[[File:AssignFileExample.png|frameless|500px]]<br> | |||
<h2> See Also </h2> | |||
* [[File_Handling | File Handling]] | |||
{{#seo:|title=AssignFile in Clomosy - Clomosy Docs}} | |||
Latest revision as of 15:14, 24 December 2024
procedure AssignFile(var FileHandle TextFile; const FileName string);
It is used to associate a file variable with a file name, enabling the program to interact with a specific file.
The `AssignFile` function creates a file variable and associates it with the specified file name.
The function takes two parameters: the first parameter is the variable corresponding to the created `TextFile` object, and the second parameter is the name of the file to be created.
In both cases, when the file is opened by Append, Reset or ReWrite, it is assumed to be in the current directory.
In the Clomosy Learn application, the file path should be specified as follows for saving files within the project directory.
AssignFile(FileHandle, Clomosy.AppFilesPath+'TaskList.txt');
Example
var
myFile : TextFile;
{
// Try to open the Test.txt file for writing to
AssignFile(myFile, Clomosy.AppFilesPath+'TaskList.txt');
ReWrite(myFile);
ShowMessage('The file is added to the directory where the exe is located.');
// Write a couple of well known words to this file
WriteLn(myFile, 'Task 1');
WriteLn(myFile, 'Task 2');
ShowMessage('Lines have been added to the file.');
// Close the file
CloseFile(myFile);
}
Output:
After the file has been saved, it appears as follows.