From Clomosy Docs

Revision as of 15:14, 24 December 2024 by ClomosyAdmin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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