最簡單的Unicode安全的實現是利用TStringList
class:
function NeedAppend(const SrcFile, DestFile: string): Boolean;
var
SrcContents: TStringList;
DestContents: TStringList;
begin
SrcContents := TStringList.Create();
DestContents := TStringList.Create();
try
SrcContents.LoadFromFile(SrcFile);
DestContents.LoadFromFile(DestFile);
Result := (Pos(SrcContents.Text, DestContents.Text) = 0);
finally
SrcContents.Free;
DestContents.Free;
end;
if not Result then
begin
Log('Contents present already, will not append');
end
else
begin
Log('Contents not present, will append');
end;
end;
雖然不是非常有效,如果文件比較大。
一旦你的版本比較這種方式來實現,你可以結合起來,與合併,這個簡單的代碼:
procedure AppendFileIfNeeded(const SrcFile, DestFile: string);
var
SrcContents: TStringList;
DestContents: TStringList;
begin
SrcContents := TStringList.Create();
DestContents := TStringList.Create();
try
SrcContents.LoadFromFile(SrcFile);
DestContents.LoadFromFile(DestFile);
if Pos(SrcContents.Text, DestContents.Text) > 0 then
begin
Log('Contents present already, will not append');
end
else
begin
Log('Contents not present, will append');
DestContents.AddStrings(SrcContents);
DestContents.SaveToFile(DestFile);
end;
finally
SrcContents.Free;
DestContents.Free;
end;
end;
我在哪裏可以找到個例? –
你使用什麼合併代碼?它是Inno安裝Pascal腳本代碼嗎?你可以把它展示給我們嗎?或者你使用外部工具? –
http://pastebin.com/Qg77yC3T這是我使用的代碼:) –