Actually file based operations generate exceptiosn or not depending on the $I compiler settings. The CloseFile operation should typically be done inside a finally block, to avoid leaving the file open in case the file handling code generates an exception. Once the input or output operations are done, you should call CloseFile.Īs an example look at the folloing code, which simply saves some numbers to a file: type The next step is usually to call Reset to open the file for reading at the beginning, Rewrite to open (or create) it for writing, and Append to add new items to the end of the file without removing the older items. Once you have declared a file variable, you can assign it to a real file in the file system using the AssignFile method. Each kind of file has its own predefined routines, as we will see later in this chapter. Alternatively, you can use the TextFile type, defined in the System units to declare files of ASCII characters. It is also possible to use the file keyword without indicating a data type, to specify an untyped file. You use file to define a new type, and then you can use the new data type to declare new variables: type As you might recall from Chapter 2, the language has a file keyword, which is a type specifier, like array or record. One of the peculiarities of Pascal compared with other programming languages is its built-in support for files. The cover of the 4th edition of Essential Pascal,
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |