From Free Pascal wiki
Jump to: navigation, search

Deutsch (de) English (en) français (fr) Bahasa Indonesia (id)

Dalam artikel ini, demi kemudahan pengertian, kata terpakai dalam Pascal ditampilkan dalam HURUF BESAR meskipun bahasa Pascal tidak sensitif jenis huruf.

Ketikda dipakai dalam program Pascal, file adalah variabel yang digunakan untuk mengambil data dengan membaca variabel file, atau untuk mengirimkan data ke variabel file, atau keduanya untuk pembacaan dan penulisan. File berbeda dari variabel normal dalam sebuah program dalam hal informasi di dalam file biasanya tersedia bahkan setelah program berakhir.

Format sumber Pascal adalah

VAR filname : FILE;

Di mana filname adalah variabel file yang dipakai untuk mengakses file. Kata file sendiri merupakan kata terpakai dalam Pascal.

When a file is defined in this fashion, it is called an untyped file; it may be used to store essentially anything.

A typical type of file used for plain documents is a file of char and is defined by the compiler using the shorthand name text. As such, the following two declarations should be equivalent:

VAR filname : FILE OF char;
VAR filname : text;

In the above example, the identifier used (filname) is the file variable which is used to do input, output, or both, to the actual file. The file variable, however, is not the actual file; the file variable must be tied to the actual file by a run-time library routine. In most cases, this is done via the assign procedure followed by use of the reset or rewrite procedure. In the case of specialized files such as databases, it is done via some other method than the standard ones, in order to allow a file variable to actually read from and/or write to the actual file itself using specialized routines.

A file variable is used either for input, for output, or for both input and output (I/O). A file may be a screen and/or keyboard, a modem, a light pen, a touch screen, a mouse, an area of storage on disk, a socket for connecting to the Internet, or it could be some other device depending on how the run-time library ties the file. In some cases, actual memory can be defined as a file; this was used in the case of a ram disk.

Some of these devices are connected through various specialized libraries instead of treating them as actual files. For example, databases are not normally accessed directly as a simple file which is read or written, they are usually accessed either through a set of database handling procedures and functions in an external unit or library, or are accessed via SQL commands sent to a procedure or function. Programs that communicate with the Internet usually use a set of routines called sockets under Unix-based operating systems, or using the Winsock routines on Microsoft Windows, which essentially provide the same functions as the Unix sockets routines.

Generally, the standard Pascal language does not distinguish between types of files, treating all files the same, allowing them to be accessed via the read, readln, write and writeln standard procedures. Some Pascal Compilers also used the Get and Put routines for I/O.

Enhanced versions of Pascal such as UCSD Pascal, Turbo Pascal, and, of course, FPC Pascal have added features to indicate that a file is specifically a screen or a disk file, and to allow for such functions as naming of disk files, random access, appending to the end and deleting of files as needed.

File-related types, procedures and functions:

File - Text - AssignFile - CloseFile - Reset - Rewrite - Get - Put - Read - Readln - Write - Writeln