Wenn du den Dateizugriff in einem Interface kapselst, dann hast du deinen GC.
Delphi-Quellcode:
AssignFile(f, ''); // oder TFileRec(f).Mode := fmClosed;
for i:= 1 to 5 do
begin
if TFileRec(f).Mode <> fmClosed then CloseFile(f);
AssignFile(f, 'PathToFile' + IntToStr(i));
Reset(f);
...
end;
if TFileRec(f).Mode <> fmClosed then CloseFile(f);
Delphi-Quellcode:
AssignFile(f, ''); // oder TFileRec(f).Mode := fmClosed;
try
for i:= 1 to 5 do
begin
if TFileRec(f).Mode <> fmClosed then CloseFile(f);
AssignFile(f, 'PathToFile' + IntToStr(i));
Reset(f);
...
end;
finally
if TFileRec(f).Mode <> fmClosed then CloseFile(f);
end;
aber besser doch so
Delphi-Quellcode:
for i:= 1 to 5 do
begin
AssignFile(f, 'PathToFile' + IntToStr(i));
Reset(f);
try
...
finally
CloseFile(f);
end;
end;