I. Old Pascal file type
A file type, such as F:text,f:file, that is represented by a file variable. Defines three classes: there are types, no types, character types, and some Delphi file manipulation functions. For example: Assignprn,writeln, these file classes are incompatible with Windows file handles
Two. Windows file handle (handle)
Object-oriented Pascal's file handle encapsulates the Windows file handle type, and the file Manipulation function library encapsulates Windows API functions, such as "Fileread", which calls the Windows API number "ReadFile". Delphi provides a Windows API operator interface if you are familiar with the Windows API, you can use Windows file sentences for file operations.
Three. File Flow (Streams)
The file stream is an object instance of the TFileStream class, and the file stream is the top-level file-handling type, and TFileStream provides a handle property. Use this property to manipulate the Windows file handle type.
How to select a file type
Windows file handles are lower-level file operation types, providing flexible synchronous and asynchronous file read and write control, and the following provides pseudo code descriptions of file synchronization and asynchronous operations with Windows file handle types:
Sync Action:
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead, NULL) ;
// check for eof
if (bResult && nBytesRead == 0, ) {
// we"re at the end of the file
}
Asynchronous Operation:
Set up OVERLAPPED structure fields
Goverlapped.offset = 0;
Goverlapped.offsethigh = 0;
Goverlapped.hevent = NULL;
Attempt an asynchronous read operation
Bresult = ReadFile (hfile, &inbuffer, Nbytestoread, &nbytesread,
&goverlapped);
If there was a problem, or the async. Operation "s still pending ...
if (!bresult)
{
Deal with the error code
Switch (dwerror = GetLastError ())
{
Case ERROR_HANDLE_EOF:
{
We re reached the end of the file
During the call to ReadFile
Code to handle that
}
Case Error_io_pending:
{
asynchronous I/O still in progress
Do something else for a while
Godosomethingelse ();
Check on the results of the asynchronous read
Bresu = GetOverlappedResult (hfile, &goverlapped,
&nbytesread, FALSE);
If there was a problem ...
if (!bresult)
{
Deal with the error code
Switch (dwerror = GetLastError ())
{
Case ERROR_HANDLE_EOF:
{
We re reached the end of the file
File://during/asynchronous operation
}
Deal with the other error cases
}
}
}//End case
Deal with the other error cases
}//End switch
}//End If