进入旧版 | 服务项目 | 成功案例 | 联系方式 | 过客留言 | 友情链接
   
设为首页
加入收藏
联系我们
网站首页 | 新闻资讯 | 操作系统 | 办公软件 | 网络软件 | 工具软件 | 媒体动画 | 网页制作 | 网站开发 | 程序开发 | 平面设计
Photoshop视频教程 | Word入门 | Flash入门 | JScript | VBScript | ASP | PHP | ADO | 网页特效 | 3DS MAX6.0命令 | 系统进程
您当前的位置:GOODSGY电脑学习网 -> 程序开发 -> DLEPHI -> 文章内容  
Delphi中用于读写(I/O)的三种文件类型

Delphi中用于读写(I/O)的三种文件类型www.goodsgy.com

一.旧pascal文件类型
    用旧文件变量表示的文件类型,比如 F:text,F:File. 定义了三类:有类型,无类型,字符类型以及一些Delphi的文件操作函数.比如:AssignPrn,Writeln,这些文件类和Windows文件句柄不兼容www.goodsgy.com

二.Windows文件句柄(handle)
    面向对象的Pascal的文件句柄封装了Windows文件句柄类型,文件操作函数库则封装了Windows API函数,比如"Fileread"就是调用了Windows API 函数"ReadFile",Delphi提供了一个Windows API操作接口如果熟悉Windows API,可以用Windows文件句进行文件操作.www.goodsgy.com

三.文件流(File Streams)
    文件流是TFileStream类的对象实例,文件流是高层的文件操作类型,TFileStream提供了一个句柄属性.用此属性可操作Windows文件句柄类型.www.goodsgy.com

如何选择文件类型www.goodsgy.com

      Windows文件句柄是较底层的文件操作类型,提供了灵活的同步及异步文件读写控制,以下提供用Windows文件句柄类型对文件同步及异步操作的伪代码描述:
同步操作:
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead, NULL) ;
// check for eof
if (bResult &&  nBytesRead == 0, ) {
 // we're at the end of the file
 } www.goodsgy.com

异步操作:
// 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()) www.goodsgy.com

    {
        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 is still in progress
 
            // do something else for a while
            GoDoSomethingElse() ;
 
            // check on the results of the asynchronous read
            bResult = GetOverlappedResult(hFile, &gOverlapped, www.goodsgy.com

                &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 other error cases www.goodsgy.com

                }
            }
        } // end case
 
        // deal with other error cases
 
    } // end switch
} // end if
 
虽然Windows文件句柄提供灵活的文件控制,但须编写更多的出错处理代码,如果对
WindowsAPI不熟悉,使用Delphi推荐的旧文件变量类型.www.goodsgy.com

       Delphi的旧文件类型使用AssignFile,使文件变量和物理文件关联,通过Delphi定义的
对文件变量的各种操作,完成文件的存取和操作.使用方便.以下提供对文件变量类
型的操作代码描述:
var www.goodsgy.com

  F: TextFile;
  S: string;
begin
  if 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;www.goodsgy.com

      文件流是流(stream classes)的子类,所以使用他的一个优点就是能自动继承其父类的属性他能很容易的和其他的流类互操作,比如你如果想把一块动态内存块写入磁盘,可以使用一个TFileStream和一个TMemoryStream来完成.www.goodsgy.com

在百度中搜索:Delphi中用于读写(I/O)的三种文件类型
在Google中搜索:Delphi中用于读写(I/O)的三种文件类型
在Yahoo中搜索:Delphi中用于读写(I/O)的三种文件类型

收藏到网摘:新浪VIVI 365key 我摘 POCO网摘 博采中心 YouNote 和讯网摘 天天收藏
[] [返回上一页] [打 印] [收 藏]
上一篇文章:Delphi嵌入式汇编一例

 相关文章    最新文章
· Total Commander无法处理桌面文件怎么办?..
· Linux hosts.allow与hosts.deny限制访问
· [图文] Windows Live Folders 新鲜试用
· Pixar发布支持Maya的RenderMan学习版
· 小技巧:如何用Delphi创建快捷方式
· php脚本中include文件报错解决方法
· Delphi版模仿熊猫烧香病毒核心源码
· Delphi“判断服务器路径”与“清空日志文..
· [图文] 滤镜之BladePro
· adgjdet.exe
 
· 小技巧:如何用Delphi创建快捷方式
· Delphi版模仿熊猫烧香病毒核心源码
· Delphi“判断服务器路径”与“清空日志文..
· 应用程序敏感键的实现
· 用Delphi实现远程屏幕抓取
· 用DEPHI为应用软件建立注册机制
· 利用Hook技术实现键盘监控
· Delphi编程实现Ping操作
· 通用Delphi数据库输入控件DBPanel的实现
· 用Delphi开发屏幕保护预览程序

∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论…]
站内搜索

精彩图文
  网站导航  
操作系统 办公软件 网络软件
Vista Windows2003 WindowsXP Windows2000/NT Windows9X/ME Linux 其他 Word Excel Powerpoint Outlook 金山系列 其他 网页浏览 上传下载 联络聊天 邮件工具 服务器软件 网络辅助
工具软件 媒体动画 网页制作
系统工具 媒体工具 压缩工具 图文处理 文件管理 其他 3DMAX Authorware Director Maya 视频处理 其他 Flash Dreamweaver FireWorks FrontPage LiveMotion Golive HTML/CSS 其它
网站开发 平面设计 程序设计
ASP JSP PHP CGI JavaScript VBScript XML/SOAP Web服务器 Photoshop PhotoImpact CorelDraw Illustrator Freehand 设计欣赏 其他 VB VC .NET C/C++ DELPHI JAVA

冀ICP备05019428号
Copyright © 2004-2008 电脑学习网 Inc.All rights reserved.
TEL:13832340607
QQ:39873155
E_Mail:goodsgy(#)hotmail.com   (把(#)替换成@)
MSN:goodsgy(#)hotmail.com   (把(#)替换成@)