我是一个新手,请高手们帮我看看下面的这段代码错在哪,我在这先谢谢大家了:
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.