inno-setup – 使用Inno Setup替换文件中的文本
发布时间:2020-12-15 10:12:33 所属栏目:大数据 来源:网络整理
导读:您好我用Inno Setup(基于Delphi)替换文本文件中的文本有问题. 我的代码: procedure FileReplaceString(const FileName,searchstring,replacestring: string);var fs: TFileStream; S: string;begin fs := TFileStream.Create(FileName,fmOpenread or fmShar
|
您好我用Inno Setup(基于Delphi)替换文本文件中的文本有问题.
我的代码: procedure FileReplaceString(const FileName,searchstring,replacestring: string);
var
fs: TFileStream;
S: string;
begin
fs := TFileStream.Create(FileName,fmOpenread or fmShareDenyNone);
try
SetLength(S,fs.Size);
fs.ReadBuffer(S[1],fs.Size);
finally
fs.Free;
end;
{ the compiler stops here with: unknown identifier 'StringReplace' }
S := StringReplace(S,SearchString,replaceString,[rfReplaceAll,rfIgnoreCase]);
fs := TFileStream.Create(FileName,fmCreate);
try
fs.WriteBuffer(S[1],Length(S));
finally
fs.Free;
end;
end;
我发现我必须使用StringChange(),但我不知道如何将它与我的代码一起使用.我不太了解Delphi或Inno Setup. 解决方法
我希望这个功能完成这项工作:
function FileReplaceString(const FileName,ReplaceString: string):boolean;
var
MyFile : TStrings;
MyText : string;
begin
MyFile := TStringList.Create;
try
result := true;
try
MyFile.LoadFromFile(FileName);
MyText := MyFile.Text;
{ Only save if text has been changed. }
if StringChangeEx(MyText,ReplaceString,True) > 0 then
begin;
MyFile.Text := MyText;
MyFile.SaveToFile(FileName);
end;
except
result := false;
end;
finally
MyFile.Free;
end;
end;
感谢TLama提供反馈意见. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
