D
depale
Unregistered / Unconfirmed
GUEST, unregistred user!
最近在编一个小程序时遇到一个问题苦思冥想不知所措,请各位帮忙点拨一下,谢谢!
我的问题如下:
为什么我用了一个按钮,代码如下:
if OpenDialog1.Excute then
begin
Edit1.Text:=OpenDialog1.FileName;
end;
运行时,单击另一个按钮(代码如下"Add")把Edit1.Text添加到记录里就不动了
(只要通过以上代码实现的就"搁了",手工输入的就行了),代码如下:
定义类型:
type
DataRecord = Record
Name:String[10];
Rec:String[100];
Start:String[6];
Ent:String[6];
end;
--------------------------------
procedure TForm1.ReadData;
var
Count,i:integer;
str:string;
begin
str:='data.txt';
AssignFile(DataFile,str);
if FileExists(str) then
begin
Reset(DataFile);
Count:=FileSize(DataFile);
StatusBar1.Panels[1].Text:='共有'+IntToStr(Count)+'条记录!';
if Count>0 then
begin
StringGrid1.RowCount:=Count+1;
for i:=1 to Countdo
begin
Read(DataFile,Data);
StringGrid1.Cells[0,i]:=Data.Name;
StringGrid1.Cells[1,i]:=Data.Rec;
StringGrid1.Cells[2,i]:=Data.Start;
StringGrid1.Cells[3,i]:=Data.Ent;
end;
end
else
StringGrid1.Rows[1].Clear;
end
else
begin
Rewrite(DataFile);
end;
end;
-----------------------------------
procedure TForm3.Add;
var
Count:integer;
begin
with Form1do
begin
str:='data.txt';
Data.Name:=ComboBox1.Text;
Data.Rec:=Edit1.Text;
Data.Start:=MaskEdit1.Text;
Data.Ent:=MaskEdit2.Text;
AssignFile(DataFile,str);
if FileExists(str) then
begin
Reset(DataFile);
Count:=FileSize(DataFile);
Seek(DataFile,Count);
Write(DataFile,Data);
ReadData;
StringGrid1.RowCount:=Count+2;
StringGrid1.Row:=StringGrid1.RowCount-1;
end;
end;
end;
我的问题如下:
为什么我用了一个按钮,代码如下:
if OpenDialog1.Excute then
begin
Edit1.Text:=OpenDialog1.FileName;
end;
运行时,单击另一个按钮(代码如下"Add")把Edit1.Text添加到记录里就不动了
(只要通过以上代码实现的就"搁了",手工输入的就行了),代码如下:
定义类型:
type
DataRecord = Record
Name:String[10];
Rec:String[100];
Start:String[6];
Ent:String[6];
end;
--------------------------------
procedure TForm1.ReadData;
var
Count,i:integer;
str:string;
begin
str:='data.txt';
AssignFile(DataFile,str);
if FileExists(str) then
begin
Reset(DataFile);
Count:=FileSize(DataFile);
StatusBar1.Panels[1].Text:='共有'+IntToStr(Count)+'条记录!';
if Count>0 then
begin
StringGrid1.RowCount:=Count+1;
for i:=1 to Countdo
begin
Read(DataFile,Data);
StringGrid1.Cells[0,i]:=Data.Name;
StringGrid1.Cells[1,i]:=Data.Rec;
StringGrid1.Cells[2,i]:=Data.Start;
StringGrid1.Cells[3,i]:=Data.Ent;
end;
end
else
StringGrid1.Rows[1].Clear;
end
else
begin
Rewrite(DataFile);
end;
end;
-----------------------------------
procedure TForm3.Add;
var
Count:integer;
begin
with Form1do
begin
str:='data.txt';
Data.Name:=ComboBox1.Text;
Data.Rec:=Edit1.Text;
Data.Start:=MaskEdit1.Text;
Data.Ent:=MaskEdit2.Text;
AssignFile(DataFile,str);
if FileExists(str) then
begin
Reset(DataFile);
Count:=FileSize(DataFile);
Seek(DataFile,Count);
Write(DataFile,Data);
ReadData;
StringGrid1.RowCount:=Count+2;
StringGrid1.Row:=StringGrid1.RowCount-1;
end;
end;
end;