一直在到处搜索,但我似乎无法让它工作。当我运行此代码时,我收到一个 EFCreateError 告诉我该文件已被另一个进程使用。我对使用 TStringLists 有点陌生,所以我需要你的帮助!提前致谢!
这是产生错误的地方:empFile.SaveToFile('Data\Emp\'+emp+'\'+emp+'.txt');
procedure TfmMain.btSaveRetClick(Sender: TObject);
var
select, pos1, pos2, pos3, i: integer;
fileBuffer, rentFile: TextFile;
rCode, emp, buffer, retBuffer: string;
empFile: TStringList;
begin
if lbReturn.Items.Count <> 0 then
begin
select:=Messagedlg('Retourner les items?', mtConfirmation, [mbYes, mbNo],0);
if select=mrYes then
begin
empFile:=TStringList.Create;
AssignFile(fileBuffer, 'Data\filebuffer.dat');
AssignFile(rentFile, 'Data\rented.dat');
lbReturn.Items.SaveToFile('Data\filebuffer.dat');
Reset(fileBuffer);
Reset(rentFile);
repeat
begin
ReadLn(fileBuffer, buffer);
pos1:=AnsiPos('|', buffer);
rCode:=AnsiLeftStr(buffer, pos1-2);
repeat
begin
ReadLn(rentFile, retBuffer);
pos2:=AnsiPos(rCode, retBuffer);
if pos2<>0 then
begin
pos3:=AnsiPos('|', retBuffer);
emp:=AnsiRightStr(retBuffer, (Length(retBuffer))-pos3-1);
empFile.LoadFromFile('Data\Emp\'+emp+'\'+emp+'.txt');
i:=empFile.IndexOf(buffer);
empFile.Delete(i);
empFile.SaveToFile('Data\Emp\'+emp+'\'+emp+'.txt');
empFile.Clear;
end;
end;
until EOF(rentFile);
end;
until EOF(fileBuffer);
empFile.Free;
end;
end
else
begin
MessageDlg('Aucun item à enregistrer!', mtError, [mbOK], 0);
end;
end;