Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 根据Inno安装程序中的用户首选项编辑安装的文件_Xml_Config_Inno Setup_Pascalscript - Fatal编程技术网

Xml 根据Inno安装程序中的用户首选项编辑安装的文件

Xml 根据Inno安装程序中的用户首选项编辑安装的文件,xml,config,inno-setup,pascalscript,Xml,Config,Inno Setup,Pascalscript,所以我已经为这个问题挣扎了几天了。 目前正在为我们公司的软件制作安装程序,但客户必须能够填写保存在app.exe.config中的URL 我通过谷歌搜索找到了这段我编辑过的代码 var 自定义编辑:TEdit; CustomPageID:整数; 函数LoadValueFromXML(const-AFileName,APath:string):string; 变量 XMLNode:变体; XMLDocument:变体; 开始 结果:=''; XMLDocument:=CreateOleObject

所以我已经为这个问题挣扎了几天了。 目前正在为我们公司的软件制作安装程序,但客户必须能够填写保存在
app.exe.config
中的URL

我通过谷歌搜索找到了这段我编辑过的代码

var
自定义编辑:TEdit;
CustomPageID:整数;
函数LoadValueFromXML(const-AFileName,APath:string):string;
变量
XMLNode:变体;
XMLDocument:变体;
开始
结果:='';
XMLDocument:=CreateOleObject('Msxml2.DOMDocument');
尝试
XMLDocument.async:=False;
加载(AFileName);
如果是(XMLDocument.parseError.errorCode 0),则
MsgBox('无法分析XML文件。'+
XMLDocument.parseError.reason,mbError,MB_OK)
其他的
开始
setProperty('SelectionLanguage','XPath');
XMLNode:=XMLDocument.selectSingleNode(APath);
结果:=XMLNode.text;
结束;
除了
MsgBox('发生错误!'+#13#10+GetExceptionMessage,mbError,MB#u OK);
结束;
结束;
过程SaveValueToXML(常量AFileName、APath、AValue:string);
变量
XMLNode:变体;
XMLDocument:变体;
开始
XMLDocument:=CreateOleObject('Msxml2.DOMDocument');
尝试
XMLDocument.async:=False;
加载(AFileName);
如果是(XMLDocument.parseError.errorCode 0),则
MsgBox('无法分析XML文件。'+
XMLDocument.parseError.reason,mbError,MB_OK)
其他的
开始
setProperty('SelectionLanguage','XPath');
XMLNode:=XMLDocument.selectSingleNode(APath);
XMLNode.text:=AValue;
XMLDocument.save(文件名);
结束;
除了
MsgBox('发生错误!'+#13#10+GetExceptionMessage,mbError,MB#u OK);
结束;
结束;
程序初始化;
变量
自定义页面:TWizardPage;
开始
CustomPage:=CreateCustomPage(欢迎使用“自定义页面”,
'输入将保存到XML文件中的新值';
CustomPageID:=CustomPage.ID;
CustomEdit:=TEdit.Create(向导表单);
CustomEdit.Parent:=CustomPage.Surface;
结束;
过程CurPageChanged(CurPageID:Integer);
开始
如果CurPageID=CustomPageID,则
开始
自定义编辑。文本:=
LoadValueFromXML('C:\AutoScan.exe.config',
“//配置/system.serviceModel/client/endpoint/address”);
结束;
结束;
函数NextButtonClick(CurPageID:Integer):布尔值;
开始
结果:=真;
如果CurPageID=CustomPageID,则
开始
SaveValueToXML(
'C:\AutoScan.exe.config',
'//configuration/system.serviceModel/client/endpoint/address',CustomEdit.Text);
结束;
结束;
如果我指定一个像
C:\AutoScan.exe.config
这样的现有路径,它就会执行必须执行的操作,但是如果文件不存在,安装程序就会开始抱怨。
当然,该文件仅在安装后才存在。但在本例中,我希望在安装程序中编辑该文件,我使用“{src}\AutoScan.exe.config”和“{app}\AutoScan.exe.config”进行了尝试,但没有结果,因为安装程序开始抱怨找不到XML文件

,您可能只需要在安装完成后编辑该文件

过程CurStepChanged(CurStep:TSetupStep);
开始
如果CurStep=ssPostInstall,则
开始
SaveValueToXML(
'C:\AutoScan.exe.config',
'//configuration/system.serviceModel/client/endpoint/address',CustomEdit.Text);
结束;
结束;

此外,您不应该在每次访问自定义页面时都加载该值,因为每次用户返回自定义页面时都会重置用户首选项

您应该在
初始化向导中只加载一次

要么硬编码默认值

或者,如果您确实需要从嵌入的文件中读取它,则必须临时提取它

程序初始化;
变量
自定义页面:TWizardPage;
开始
自定义页面:=
创建自定义页面(
欢迎使用“自定义页面”,
'输入将保存到XML文件中的新值';
CustomEdit:=TEdit.Create(向导表单);
CustomEdit.Parent:=CustomPage.Surface;
提取临时文件('AutoScan.exe.config');
自定义编辑。文本:=
LoadValueFromXML(
ExpandConstant(“{tmp}\AutoScan.exe.config”),
“//配置/system.serviceModel/client/endpoint/address”);
结束;

安装完成后,您可能只需要编辑文件

过程CurStepChanged(CurStep:TSetupStep);
开始
如果CurStep=ssPostInstall,则
开始
SaveValueToXML(
'C:\AutoScan.exe.config',
'//configuration/system.serviceModel/client/endpoint/address',CustomEdit.Text);
结束;
结束;

此外,您不应该在每次访问自定义页面时都加载该值,因为每次用户返回自定义页面时都会重置用户首选项

您应该在
初始化向导中只加载一次

要么硬编码默认值

或者,如果您确实需要从嵌入的文件中读取它,则必须临时提取它

程序初始化;
变量
自定义页面:TWizardPage;
开始
自定义页面:=
创建自定义页面(
欢迎使用“自定义页面”,
'输入将保存到XML文件中的新值';
CustomEdit:=TEdit.Create(向导表单);
CustomEdit.Parent:=CustomPage.Surface;
提取临时文件('AutoScan.exe.config');
自定义编辑。文本:=
LoadValueFromXML(
ExpandConstant(“{tmp}\AutoScan.exe.config”),
“//配置/system.serviceModel/client/endpoint/address”);
结束;