var
     numread,numwirtten:integer;
     fromf,tof:file;      //源文件和目标文件
     buf:array[0..2048] of char; //定义的缓冲区;
    .....
    ....
    repeat
    blockread(fromf,buf,sizeof(buf),numread); //从源文件往缓冲区中读; 
    blockwrite(tof,buf,numread,numwritten) ;
    until(numread=0) or (numwritten <>  numread) ;
    ...............
   
      在   blockread(fromf,buf,sizeof(buf),numread
           blockwrite(tof,buf,numread,numwritten)
           中的参数 fromf,tof 分别是 源文件名和 目标文件名 
           但是  numread ,numwritten 又是什么意思呢?它们在
           blockread() 和 blockwrite()中的作用是什么呢?
           请赐教,最好可以给举个例子。
           多谢了!!      还有就是  (numread=0) or (numwrite<> numread)  这个语句的作用。
       (numread=0) 和 (numwrite<> numread)在上面程序中的具体作用是什么呀?
       多谢了!!    

解决方案 »

  1.   

    numread是已经读取的数据块的数量,主要用来和前面的sizeof(buf)——应该读取的数据块数量进行比较。sizeof(buf)这个只应该在传输前指定,如果不指定为128。
    在传输完成的情况下,sizeof(buf)应该和numread是相等的。
    numwritten跟numread类似,只不过是已经写入的数据块的数量而已;
    那个(numread=0) or (numwrite<> numread)就是说:
    只要读取时不发生两种错误时就继续循环
    1.没读到数据,比如说要读出的文件为空
    2.读和写的数量不一致
    明白了吗?
      

  2.   

    Delphi syntax:procedure BlockRead(var F: File; var Buf; Count: Integer [; var AmtTransferred: Integer]);DescriptionF is an untyped file variable, Buf is any variable, Count is an expression of type Integer, and AmtTransferred is an optional variable of type Integer.BlockRead reads Count or fewer records from the file F into memory, starting at the first byte occupied by Buf. The actual number of complete records read (less than or equal to Count) is returned in AmtTransferred.//BlockRead从文件F中读和Count一样或比它少的记录到内存,从Buf的第一个字节开始。//Count是你希望读的记录数,而实际读的记录数保存在AmtTransferred中The entire transferred block occupies at most Count * RecSize bytes. RecSize is the record size specified when the file was opened (or 128 if the record size was not specified).If the entire block was transferred, AmtTransferred is equal to Count.If AmtTransferred is less than Count, ReadBlock reached the end of the file before the transfer was complete. If the file's record size is greater than 1, AmtTransferred returns the number of complete records read.If AmtTransferred isn't specified, an I/O error occurs if the number of records read isn't equal to Count. If the $I+ compiler directive is in effect, errors raise an EInOutError exception.