标题:[求助]一段关于DELPHI代码的出错原因
只看楼主
cch8080
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-3-18
结帖率:100%
 问题点数:0 回复次数:6 
[求助]一段关于DELPHI代码的出错原因

我是一个新手,请高手们帮我看看下面的这段代码错在哪,我在这先谢谢大家了:
unit unit2;

interface

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

type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Button1: TButton;
Button2: TButton;
ListBox1: TListBox;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
type
studentrecord=record
xh,xm:string[6];
yw,sx,wy:integer;
end;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var t:studentrecord;
f:file of studentrecord;
begin
assignfile(f,'c:\my documents\文件.dat');
if fileexists('c:\my documents\文件.dat') then
reset(f)
else
rewrite(f);
while not eof(f) do
begin
read(f,t);
listbox1.Items.Add(t.xh+''+t.xm+''+inttostr(t.yw)+''+inttostr(t.wy)+''+inttostr(t.sx));
end;
closefile(f);
button3.Enabled:=false;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
edit5.Text:='';
end;

procedure TForm1.Button2Click(Sender: TObject);
var t:studentrecord;
f:file of studentrecord;
size:integer;
begin
t.xh:=edit1.Text;
t.xm:=edit2.Text;
t.yw:=strtoint(edit3.Text);
t.wy:=strtoint(edit4.Text);
t.sx:=strtoint(edit5.Text);
assignfile(f,'c:\my documents\文件.dat');
reset(f);
size:=filesize(f);
seek(f,size); //将文件指针移至文件位置
write(f,t);
listbox1.Items.Clear;
seek(f,0);
while not eof(f) do
begin
read(f,t);
listbox1.Items.Add(t.xh+''+t.xm+''+inttostr(t.yw)+''+inttostr(t.wy)+''+inttostr(t.sx));

end;
closefile(f);
end;

procedure TForm1.Button3Click(Sender: TObject);
var pos:integer;
t:studentrecord;
f:file of studentrecord;
begin
pos:=listbox1.ItemIndex;
assignfile(f,'c:\my documents\文件.dat');
reset(f);
seek(f,pos+1);
while not eof(f) do
begin
read(f,t);
seek(f,pos);
pos:=pos+1;
write(f,t);
seek(f,pos+1);
end;
seek(f,pos);
truncate(f); //截去当前位置后的所有数据
seek(f,0);
listbox1.Items.Clear;
while not eof(f) do
begin
read(f,t);
listbox1.Items.Add(t.xh+''+t.xm+''+inttostr(t.yw)+''+inttostr(t.wy)+''+inttostr(t.sx));
end;
closefile(f);
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
if listbox1.itemindex>1 then
button3.Enabled:=true
else
button3.Enabled:=false;
end;

end.

搜索更多相关主题的帖子: DELPHI 代码 
2007-04-22 07:43
phonbob
Rank: 1
等 级:新手上路
威 望:1
帖 子:57
专家分:0
注 册:2007-4-21
得分:0 
你错误提示在哪行?

男儿、血如泪、洒沙场
2007-04-22 14:50
cch8080
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-3-18
得分:0 
错误提示是下面的:rewrite(f),然后我把rewrite(f)改成write(f)再运行错误提示就变成while not eof(f) then这一行,提示信息和之前的一样.我都被高晕了,请您多多指教,谢了!!
procedure TForm1.FormCreate(Sender: TObject);
var t:studentrecord;
f:file of studentrecord;
begin
assignfile(f,'c:\my documents\文件.dat');
if fileexists('c:\my documents\文件.dat') then
reset(f)
else
rewrite(f); 这行是错误提示,好象说是:INVALID FILENAME
while not eof(f) do
begin
2007-04-22 16:18
zshoucheng
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-3-11
得分:0 
别用中文文件名``
2007-04-22 18:53
cch8080
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-3-18
得分:0 

该为英文名也不行,请高手们帮帮忙!谢谢大家!

2007-04-23 17:58
anthony634
Rank: 6Rank: 6
来 自:西南交大
等 级:贵宾
威 望:24
帖 子:653
专家分:10
注 册:2006-6-8
得分:0 

我用delphi6编译你的程序能通过编译,错误可能是在unit1里的,我看你这是unit2

2007-04-23 18:41
cch8080
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-3-18
得分:0 

应该不是那个unit2的问题,因为我在这之前已经保存了一个unit1的文件,我想会不会是版本的问题,因为我用的是DELPHI 6.0书本上的代码编的,而我用的是DELPHI 7。0的编译器

2007-04-24 16:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-133919-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045230 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved