1 2 3 ÏÂÒ»Ò³ ¡¡¡Ò».¾ÉpascalÎļþÀàÐÍ
¡¡¡¡ÓÃÎļþ±äÁ¿±íʾµÄÎļþÀàÐÍ,±ÈÈç F:text,F:File. ¶¨ÒåÁËÈýÀà:ÓÐÀàÐÍ,ÎÞÀàÐÍ,×Ö·ûÀàÐÍÒÔ¼°Ò»Ð©DelphiµÄÎļþ²Ù×÷º¯Êý.±ÈÈç:AssignPrn,Writeln,ÕâЩÎļþÀàºÍWindowsÎļþ¾ä±ú²»¼æÈÝ
¡¡¡¡¶þ.WindowsÎļþ¾ä±ú(handle)
¡¡¡¡ÃæÏò¶ÔÏóµÄPascalµÄÎļþ¾ä±ú·â×°ÁËWindowsÎļþ¾ä±úÀàÐÍ,Îļþ²Ù×÷º¯Êý¿âÔò·â×°ÁËWindows APIº¯Êý,±ÈÈç"Fileread"¾ÍÊǵ÷ÓÃÁËWindows
APIÊý"ReadFile",DelphiÌṩÁËÒ»¸öWindows API²Ù×÷½Ó¿ÚÈç¹ûÊìϤWindows API£¬¿ÉÒÔÓÃWindowsÎļþ¾ä½øÐÐÎļþ²Ù×÷.
¡¡¡¡Èý.ÎļþÁ÷(File Streams)
¡¡¡¡ÎļþÁ÷ÊÇTFileStreamÀàµÄ¶ÔÏóʵÀý,ÎļþÁ÷ÊǸ߲ãµÄÎļþ²ÙÀàÐÍ,TFileStreamÌṩÁËÒ»¸ö¾ä±úÊôÐÔ.ÓôËÊôÐԿɲÙ×÷WindowsÎļþ¾ä±úÀàÐÍ.
¡¡¡¡ÈçºÎÑ¡ÔñÎļþÀàÐÍ
¡¡¡¡WindowsÎļþ¾ä±úÊǽϵײãµÄÎļþ²Ù×÷ÀàÐÍ,ÌṩÁËÁé»îµÄͬ²½¼°Òì²½Îļþ¶Áд¿ØÖÆ,ÒÔÏÂÌṩÓÃWindowsÎļþ¾ä±úÀàÐͶÔÎļþͬ²½¼°Òì²½²Ù×÷µÄα´úÂëÃèÊö:
¡¡¡¡Í¬²½²Ù×÷:
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead, NULL)
;
// check for eof
if (bResult && nBytesRead == 0, ) {
// we"re at the end of the file
}
1 2 3 ÏÂÒ»Ò³ |