From Clomosy Docs

No edit summary
No edit summary
 
Line 42: Line 42:
<h2> See Also </h2>
<h2> See Also </h2>
* [[File_Handling | File Handling]]
* [[File_Handling | File Handling]]
{{#seo:|title=AssignFile in Clomosy - Clomosy Docs}}

Latest revision as of 15:14, 24 December 2024

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.

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.

AssignFileExample.png

See Also