Delphi用于读写的种文件类型

上传人:206****923 文档编号:45912650 上传时间:2018-06-20 格式:PDF 页数:4 大小:43.94KB
返回 下载 相关 举报
Delphi用于读写的种文件类型_第1页
第1页 / 共4页
Delphi用于读写的种文件类型_第2页
第2页 / 共4页
Delphi用于读写的种文件类型_第3页
第3页 / 共4页
Delphi用于读写的种文件类型_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《Delphi用于读写的种文件类型》由会员分享,可在线阅读,更多相关《Delphi用于读写的种文件类型(4页珍藏版)》请在金锄头文库上搜索。

1、Delphi用于读写的三种文件类型Delphi用于读写的三种文件类型一.旧pascal文件类型 用旧文件变量表示的文件类型,比如 f:text,f:file. 定义了三类:有类型,无类型,字符类型以及一些delphi的文件操作函数.比如:assignprn,writeln,这些文件类和windows文件句柄不兼容 二.windows文件句柄(handle) 面向对象的pascal的文件句柄封装了windows文件句柄类型,文件操作函数库则封装了windows api函数,比如“fileread“就是调用了windows api 函数“readfile“,delphi提供了一个windows a

2、pi操作接口如果熟悉windows api,可以用windows文件句进行文件操作. 三.文件流(file streams) 文件流是tfilestream类的对象实例,文件流是高层的文件操作类型,tfilestream提供了一个句柄属性.用此属性可操作windows文件句柄类型. 如何选择文件类型 windows文件句柄是较底层的文件操作类型,提供了灵活的同步及异步文件读写控制,以下提供用windows文件句柄类型对文件同步及异步操作的伪代码描述: 同步操作: bresult = readfile(hfile, / check for eof if (bresult goverlapped.

3、offsethigh = 0; goverlapped.hevent = null; / attempt an asynchronous read operation bresult = readfile(hfile, / if there was a problem, or the async. operations still pending . if (!bresult) / deal with the error code switch (dwerror = getlasterror() case error_handle_eof: / were reached the end of

4、the file / during the call to readfile / code to handle that case error_io_pending: / asynchronous i/o is still in progress / do something else for a while godosomethingelse() ; / check on the results of the asynchronous read bresult = getoverlappedresult(hfile, / if there was a problem . if (!bresu

5、lt) 2/ deal with the error code switch (dwerror = getlasterror() case error_handle_eof: / were reached the end of the file file during asynchronous operation / deal with other error cases / end case / deal with other error cases / end switch / end if 虽然windows文件句柄提供灵活的文件控制,但须编写更多的出错处理代码,如果对 windowsa

6、pi不熟悉,使用delphi推荐的旧文件变量类型. delphi的旧文件类型使用assignfile,使文件变量和物理文件关联,通过delphi定义的 对文件变量的各种操作,完成文件的存取和操作.使用方便.以下提供对文件变量类 型的操作代码描述: var f: textfile; s: string; begin 3if opendialog1.execute then display open dialog box begin assignfile(f, opendialog1.filename); file selected in dialog box reset(f); readln(f, s); read the first line out of the file edit1.text := s; put string in a tedit control closefile(f); end; end; 文件流是流(stream classes)的子类,所以使用他的一个优点就是能自动继承其父类的属性他能很容易的和其他的流类互操作,比如你如果想把一块动态内存块写入磁盘,可以使用一个tfilestream和一个tmemorystream来完成.(作者:meiys) 4

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号