From Clomosy Docs
No edit summary |
No edit summary |
||
| Line 14: | Line 14: | ||
:'''Base Syntax''' | :'''Base Syntax''' | ||
var | var | ||
myFile : TextFile; | |||
begin | begin | ||
// 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); | |||
end; | end; | ||
:'''TRObject Syntax''' | :'''TRObject Syntax''' | ||
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:'''<br> | |||
After the file has been saved, it appears as follows. | |||
[[File:AssignFileExample.png|frameless|500px]] | |||
Revision as of 07:50, 1 August 2024
The AssignFile procedure assigns a value for a FileName in preparation for reading or writing to that file.
Version 1
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.
Version 2
Takes a binary file variable type as the handle. The file is treated as a binary file.
In both cases, when the file is opened by Append, Reset or ReWrite, it is assumed to be in the current directory.
Example:
- Base Syntax
var
myFile : TextFile;
begin
// 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);
end;
- TRObject Syntax
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.