DelayTime(10);是延时函数:
procedure TForm1.DelayTime(DeTime:integer);
var
bt:Integer;
begin
bt:=Gettickcount;
while gettickcount<bt+DeTime do
application.ProcessMessages;
end;
procedure TForm1.DelayTime(DeTime:integer);
var
bt:Integer;
begin
bt:=Gettickcount;
while gettickcount<bt+DeTime do
application.ProcessMessages;
end;
用createfile先创建一个文本文件,然后后用assingfile去关联这文件和文件变量:
代码如下:CreateFile( pchar('F:/专题文件/'+keystring+'/'+keystring+'.txt'),
GENERIC_WRITE or Generic_read ,
FILE_SHARE_WRITE, // share mode
nil, // pointer to security attributes
CREATE_ALWAYS , // how to create
FILE_ATTRIBUTE_NORMAL , // file attributes
0 // handle to file with attributes to copy
); AssignFile(MyTextFile,Keystring+'.txt‘);
Rewrite(MyTextFile);
adoquery1.First;
try
For i:=0 to adoquery1.RecordCount-1 do
begin
info_name:=adoquery1['Info_Name'];
info_month:=adoquery1['info_month'];
writeln(MyTextFile,'Name ',info_name);
writeln(MyTextFile,'Time ',info_time);
adoquery1.Next ;
DelayTime(10);
end;
finally
begin
closeFile(MyTextFile);
showmessage('列表清单已经写完');
end;出现'列表清单已经写完';对话框后我去打开创建的文本文件说正被另一个程序占用,
但就是没向里写东西呀!
不要用Finally
试试
mytextfile:filetext;
i:integer;
begin
AssignFile(MyTextFile,'Risk.txt');
if existsfile('risk.txt') then
Append(MyTextFile)
else
rewrite(mytextfile);
adoquery1.First;
try
For i:=0 to adoquery1.RecordCount-1 do
begin
info_name:=adoquery1['Info_Name'];
info_month:=adoquery1['info_month'];
writeln(MyTextFile,'Name ');
writeln(MyTextFile,'Time ');
adoquery1.Next ;
end;
finally
begin
closeFile(MyTextFile);
showmessage('列表清单已经写完');
end;