如何释放这些 .txt 文件的内存
how do I free memory of these .txt files
使用 TXT 文件我最近看到一条消息"cannot create file ('c:.txt') the process cannot acess the file because it is being used by another process"如何释放这些 .txt 文件的内存?
我有 Nice 先生的这段代码,当我尝试更改或添加新代码时使用:ListBox1.Items.savetofile('01.txt');
"cannot create file ('c:.txt') the process cannot acess the file because it is being used by another process"
var
path: string;
SR: TSearchRec;
tempFile: TextFile;
line: string;
begin
path:= 'C:\my all txt\';
if FindFirst(path + '*.txt', faAnyFile, SR) = 0 then
begin
repeat
if (SR.Attr <> faDirectory) then
begin
AssignFile(tempFile, path + SR.Name);
Reset(tempFile);
while not Eof(tempFile) do
begin
Readln(tempFile, line);
ListBox1.Items.Add(line);
end;
end;
until FindNext(SR) <> 0;
FindClose(SR);
end;
end;
您永远不会在完成文件后关闭它们。达到 Eof(tempfile)
:
后,您需要使用 CloseFile
while not Eof(tempfile) do
begin
Readln(tempfile, line);
ListBox1.Items.Add(line);
end;
CloseFile(tempfile);
使用 TXT 文件我最近看到一条消息"cannot create file ('c:.txt') the process cannot acess the file because it is being used by another process"如何释放这些 .txt 文件的内存?
我有 Nice 先生的这段代码,当我尝试更改或添加新代码时使用:ListBox1.Items.savetofile('01.txt');
"cannot create file ('c:.txt') the process cannot acess the file because it is being used by another process"
var
path: string;
SR: TSearchRec;
tempFile: TextFile;
line: string;
begin
path:= 'C:\my all txt\';
if FindFirst(path + '*.txt', faAnyFile, SR) = 0 then
begin
repeat
if (SR.Attr <> faDirectory) then
begin
AssignFile(tempFile, path + SR.Name);
Reset(tempFile);
while not Eof(tempFile) do
begin
Readln(tempFile, line);
ListBox1.Items.Add(line);
end;
end;
until FindNext(SR) <> 0;
FindClose(SR);
end;
end;
您永远不会在完成文件后关闭它们。达到 Eof(tempfile)
:
CloseFile
while not Eof(tempfile) do
begin
Readln(tempfile, line);
ListBox1.Items.Add(line);
end;
CloseFile(tempfile);