Inno Setup在appendChild msxml中崩溃 [英] Inno Setup crashes in appendChild msxml

查看:59
本文介绍了Inno Setup在appendChild msxml中崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Inno Setup中修改xml文件-但安装程序崩溃.我尝试了不同的方法,结果得到了带有问题的示例代码

I want to modify xml file in Inno Setup - but installer crashes. I tried different things, and as result got sample code with problem

procedure testXml();
var
  xmlDocLocal, nodeLocal: Variant;
begin
try
   xmlDocLocal := CreateOleObject('MSXML2.DOMDocument');
   xmlDocLocal.async := False;
   xmlDocLocal.resolveExternals := False;
   xmlDocLocal.loadXML('<root></root>');
   nodeLocal := xmlDocLocal.CreateElement('element1');
   xmlDocLocal.documentElement.appendChild(nodeLocal);
except
end;

end;

在第二次调用期间,安装程序在appendChild方法上崩溃.我在做什么错了?

During second call, installer crashes on the appendChild method. What am I doing wrong ?

推荐答案

三个想法:首先,我们使用InnoSetup,但对我们来说,需要使用另一个以特定版本6.0结尾的字符串创建OleObject:

Three ideas: first, we're using InnoSetup, but for us the OleObject needs to be created with another string ending with the specific version 6.0:

try
    XMLDoc := CreateOleObject('MSXML2.DOMDocument.6.0');
except
    RaiseException('Please install MSXML first.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)');
end;

第二个想法:尝试将xml标头添加到代码中的XML字符串中.像这样:

Second idea: try adding an xml header to the XML string you have in your code. Like this:

xmlDocLocal.loadXML('<?xml version="1.0" encoding="UTF-8" ?><root></root>');

第三个想法:尝试检查错误(如我在第一段代码中所示).这可能会给您一个很好的主意,出了什么问题.这就是我们的操作方式(并且有效):

Third idea: try checking for errors (as I already showed in the first snippet). That might give you a pretty good idea what goes wrong. This is how we do it (and it works):

XMLDoc.load(XMLFileName);
if XMLDoc.parseError.errorCode <> 0 then
  XMLDoc.load(XMLFileName2);
if XMLDoc.parseError.errorCode <> 0 then
  RaiseException('Error on line ' + IntToStr(XMLDoc.parseError.line) + ', position ' + IntToStr(XMLDoc.parseError.linepos) + ': ' + XMLDoc.parseError.reason);

希望这对您有所帮助.难以解决的未知问题;-)

Hope this helps you. Hard to solve an unknown issue ;-)

这篇关于Inno Setup在appendChild msxml中崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆