これを実現するために、xml ファイル名を入力として受け取る簡単な手順を作成しました。この手順では、各行を解析し、その内容を一時ファイルに書き込みます。このコードは、文字列 'key="Name"' を探して各行をチェックします。
if (Pos('key="Name"', strTest) <> 0 )
value
一致が見つかった場合は、その特定の行を、カスタム ページから取得した目的のタグに置き換えます。
strTest := ' <add key="Name" value="' + strName + '"/> ';
これは一時ファイルに書き込まれます。次に、元の exe.config ファイルを削除し、一時構成ファイルの名前を exe.config ファイルに変更します (これにより、必要な変更が反映されます)。以下は、プロシージャのコード スニペット全体です。[Files] からプロシージャを呼び出すことを忘れないでください。
[Files]
Source: "HUS.exe.config"; DestDir: "{app}"; AfterInstall: ConvertConfig('HUS.exe.config')
コードスニペット
procedure ConvertConfig(xmlFileName: String);
var
xmlFile: String;
xmlInhalt: TArrayOfString;
strName: String;
strTest: String;
tmpConfigFile: String;
k: Integer;
begin
xmlFile := ExpandConstant('{app}') + '\' + xmlFileName;
tmpConfigFile:= ExpandConstant('{app}') + '\config.tmp';
strName := UserPage.Values[0] +' '+ UserPage.Values[1];
if (FileExists(xmlFile)) then begin
// Load the file to a String array
LoadStringsFromFile(xmlFile, xmlInhalt);
for k:=0 to GetArrayLength(xmlInhalt)-1 do begin
strTest := xmlInhalt[k];
if (Pos('key="Name"', strTest) <> 0 ) then begin
strTest := ' <add key="Name" value="' + strName + '"/> ';
end;
SaveStringToFile(tmpConfigFile, strTest + #13#10, True);
end;
DeleteFile(xmlFile); //delete the old exe.config
RenameFile(tmpConfigFile,xmlFile);
end;
end;