您的位置:程序门 -> delphi -> windows sdk/api



利用createfile创建文件时出错raised exception class eoleexception with message "%1已经存在"


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


利用createfile创建文件时出错raised exception class eoleexception with message '%1已经存在'
发表于:2008-01-21 15:33:26 楼主
功能:通过在edit中输入数据,然后将输入的数据保存在自己建立的dat文件中
procedure   tform1.button1click(sender:   tobject);
begin
          adodataset1.createdataset;
    if   fileexists('.\data.dat')   then
    begin
        adodataset1.savetofile   ('.\data.dat');
    end
    else
    begin
        filecreate('.\data.dat');
    end;
      with   adodataset1   do
                begin
                open;
                append;
                fieldbyname('username').asstring:=edit1.text;
                fieldbyname('password').asstring:=edit2.text;
                post;
                savetofile('.\data.dat');
                end;
      application.messagebox('数据保存成功!','应用层协议分析')   ;
      close;
    end;

end
问题:如果当前文件夹里有‘data.dat'文件,一点错误也没有,但是如果没有‘data.dat'文件时,则提示出错:
raised   exception   class   eoleexception   with   message   '%1已经存在',这是怎么回事?我不想通过数据库来存数据   ,求大家给予帮助,先谢谢了
发表于:2008-01-21 16:23:101楼 得分:0
filecreate(filename);

或者filecreate(filepath   +   filename)
发表于:2008-01-23 14:12:132楼 得分:0
用api函数createfile
文件存在会获得它的句柄,不存在时创建文件

    filehandle:=createfile(pchar(logfile),generic_write,0,nil,open_always,file_attribute_normal,0);
    if   filehandle=invalid_handle_value   then   begin
        raise   exception.create('error   when   create   file');
    end;


快速检索

最新资讯
热门点击