关于 I/O error 103 的问题(50)

S

sheng12

Unregistered / Unconfirmed
GUEST, unregistred user!
我的程序运行中在 writeln(datnew, newtxt); 处报 I/O error 103 这是为什么呀?procedure TForm1.Button1Click(Sender: TObject);var datold,datnew:textfile; i,j,k,n:integer;mes,txt,newtxt,zh,nzh,name:string; a:array [1..8]of integer;ok:boolean;begin if form1.Opentxt.Execute then begin try richedit1.Clear; richedit2.Clear; label3.Caption:=''; i:=0; j:=0; k:=1; ok:=false; assignfile(datold,opentxt.FileName); reset(datold); assignfile(datnew,copy(opentxt.FileName,1,length(opentxt.FileName)-4)+'_new.txt'); rewrite(datnew); while not eof(datold) do begin readln(datold,txt); i:=i+1; txt:=StringReplace(txt,'"','',[rfReplaceAll]); richedit1.Lines.Append(txt); for n:=1 to length(txt) do begin if pos(',',txt[n])>0 then begin a[k]:=n; k:=k+1; end; end; {if pos(',',txt)>0 then a[1]:=pos(',',txt) else a[1]:=length(txt); } zh:=trim(copy(txt,1,a[1]-1)); name:=trim(copy(txt,a[1]+1,a[2]-a[1]-1)); ADOQuery1.Active:=FALSE; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('select newzh from oldtonew where oldzh='''+zh+''''); ADOQuery1.Active:=True; if not adoquery1.IsEmpty then begin j:=j+1; nzh:=adoquery1.Fieldbyname('newzh').AsString; newtxt:=nzh+trim(copy(txt,a[1],length(txt)-a[1]+1)); writeln(datnew, newtxt); richedit2.Lines.Append(newtxt); stringgrid1.Cells[1,i]:=nzh; stringgrid1.Cells[2,i]:=name; stringgrid1.Cells[3,i]:=zh; end else begin newtxt:=zh+trim(copy(txt,a[1],length(txt)-a[1]+1)); richedit2.Lines.Append('*'+newtxt+'*'); stringgrid1.Cells[1,i]:=zh; stringgrid1.Cells[2,i]:=name; stringgrid1.Cells[3,i]:=inttostr(a[3]); writeln(datnew, newtxt); end; end; CloseFile(datold); CloseFile(datnew); mes:='共有'+inttostr(i)+'条记录'+#13+'有'+inttostr(j)+'个账号转换成功!'+#13+#13+'转换后的文件名:'+#13+copy(opentxt.FileName,1,length(opentxt.FileName)-4)+'_new.txt '; label3.Caption:='以上是转换成新账号的明细。 '+#13+mes; application.MessageBox(Pchar(mes),'成功',MB_ICONINFORMATION+MB_OK+MB_DEFBUTTON1); ok:=TRUE; finally if not ok then begin application.MessageBox ('转换失败!'+#13+#13+'请检查磁盘中的文件是否完好!'+#13+'检查完毕后重新进行转换操作!','失败',MB_ICONHAND+MB_OK+MB_DEFBUTTON1); end; end; end;end;
 
可能是读写错误,看看是否是以只读方式打开文件或者文件、文件夹的属性,还有你是否有权限。
 
不是权限的问题,我把 for n:=1 to length(txt) do begin if pos(',',txt[n])>0 then begin a[k]:=n; k:=k+1; end; end;改成 if pos(',',txt)>0 then a[1]:=pos(',',txt) else a[1]:=length(txt); 再把下面有 a[2]和a[3]的地方改一下就不报错,写入文件正常。
 
那就是你代码的问题了,调试一下
 
可我没有看出来哪里有错呀。。。
 
找到问题了,是我k:=1;的位置不对
 

Similar threads

S
回复
0
查看
950
SUNSTONE的Delphi笔记
S
S
回复
0
查看
771
SUNSTONE的Delphi笔记
S
I
回复
0
查看
567
import
I
I
回复
0
查看
612
import
I
顶部