DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: qwe0987654321
今日帖子: 4
在线用户: 10
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 hzyhx2003 (hzyhx2003) ★☆☆☆☆ -
普通会员
2004/2/16 22:05:03
标题:
请问如何打开一个文本文件?,谢谢!! 浏览:1257
加入我的收藏
楼主: 我编写了一段程序,主要是从一个文件中截取数据,在调试中发现:运行至if     if fileexists(file_path) then时程序提示‘I/O rerro 103'请问这是什么原因?
以下为源程序。请予以指领!!

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Open: TOpenDialog;
    exchange: TButton;
    exit: TButton;
    select: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    procedure exitClick(Sender: TObject);
    procedure selectClick(Sender: TObject);
    procedure exchangeClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.exitClick(Sender: TObject);
begin
close;
end;

procedure TForm1.selectClick(Sender: TObject);
begin
  if (open.execute()) then
  begin
    label3.caption:=extractfilename(open.filename);
    label4.caption:=extractfiledir(open.filename);
  end;

end;

procedure TForm1.exchangeClick(Sender: TObject);
var
  infile:textfile;
  s,s1,s2,s3,s4:string;
  fCounter,i:integer;
  file_path:string;
  sno1,sno2,sno3,sno4,:string;
begin
    file_path:=label4.caption+label3.caption;
    if fileexists(file_path) then
    begin
      assignfile(infile,file_path);
      filemode:=0;
      reset(infile);
      fCounter:=0;
      while not eof(infile) do
      begin
        readln(infile,s);
        fCounter:=fCounter+1;
          i:=pos(',',s);
          s1:=copy(s,1,i-1);
          if s1='5411' then
          sno1:=s1;
          s2:=copy(s,i+1,length(s)-i);
          i:=pos(',',s2);
          sno2:=copy(s2,1,i-1);
          s3:=copy(s2,i+1,length(s2)-i);
          i:=pos(',',s3);
          sno3:=copy(s3,1,i-1);
          s4:=copy(s3,i+1,length(s3)-i);
          i:=pos(',',s4);
          sno4:=copy(s4,1,i-1);
        end;
      end;
      closefile(infile);

end;

end.
----------------------------------------------
-
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/2/16 22:18:00
1楼:  assignfile经常这样 用TStringList * sl=new TStringList最好!
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
作者:
男 blueyestar (蓝夜孤星) ★☆☆☆☆ -
盒子活跃会员
2004/2/17 0:37:18
2楼: bios大大能不能解释一下具体怎么用呀?
----------------------------------------------
真正的程序员用C,聪明的程序员用DELPHI
作者:
男 lcjclj (lcj) ★☆☆☆☆ -
盒子活跃会员
2004/2/17 6:15:42
3楼: 好好花点时间学一下Object Pascal的语言方面:
var
  s1: TStringList;
begin
  s1 := TStringList.Create;
  try
    if FileExists(filename) then
    begin
      s1.LoadFromFile(filename)
      //Put your processing code here!
    end;
  finally
    s1.Free;
  end;
end;
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行64.45313毫秒 RSS