财管家 首页
当前位置:主页>管家婆/报表打印> 文章内容

ActiveX DLL中创建TXMLDocument错误

发布时间:2011-01-05 | QQ免费站
1楼: 我在ActiveX DLL中想使用TXMLDocument控件。这个ActiveX DLL是供页面来调用的。
我在protected中定义了一个FXML: TXMLDocument;然后写了两个方法如下

比如其中有个方法New
procedure TBusiness.New;
begin
FXML := TXMLDocument.Create(nil);
FXML.Active := true;
end;

我另外一个方法

procedure TBusiness.Set_Name(const Value: WideString);
var
intIndex: Integer;
begin
intIndex := FXML.DocumentElement.ChildNodes.IndexOf('test');
end;

我在页面中依次调用New方法和Set_Name方法。报错
Project IEXPLORE.EXE raised exception class EXMLDocError with message 'No active document'. Process stopped. Use Step or Run to continue.

2楼: 含义应该就是 “无激活的文档”,

Active方法的描述
Before you can use TXMLDocument to examine or change the contents of an XML document, it must be active. Setting Active to True causes TXMLDocument to do the following:

1. Generate a BeforeOpen event.
2. If necessary, load the DOM parser and assign the DOMImplementation property.


3. Parse the XML document specified by FileName or, if FileName is an empty string, by the XML property using the options specified by ParseOptions. If both FileName and XML are empty strings, TXMLDocument creates an empty document. The interface for the parsed document is assigned to the DOMDocument property.
4. Generate an AfterOpen event.

Note: Once the DOMDocument property is assigned, you can also use the DocumentElement property.

Setting Active to False causes TXMLDocument to do the following:

1. Generate a BeforeClose event.
2. Release all of the DOM interfaces, such as DOMDocument and DocumentElement, that represent the parsed XML document.
3. Generate an AfterClose event.

帮助里面的,应该说不设置xml内容也没有关系,No Active Document的问题倒是比较少看到,我刚刚调试的时候出现了未注册模块,寒一个,估计是我自己导入了高版本的xml的原因,楼主把代码贴全一些看看,另外给楼主个建议,我不知道这种程序正规的调试方法是什么样子的,我的办法是利用OutputDebugString('xxx函数前')
OutputDebugString('xxx函数后')


这样的方式知道哪个语句出错了,然后去网上下载一个DebugView,就可以知道是哪里出错了
初步猜测是FXML.DocumentElement.ChildNodes.IndexOf('test');错了

3楼: 帮助我看了呢,可问题还是没有解决啊

4楼: 你把代码贴全一点,特别是牵涉到FXML的地方,不过怎么是IEXPLORE.EXE 的异常,楼主写的是DLL?如 速达官网

5楼: =^0^=
又是老问题:
注意你的对象和接口不要混用
这里的 FXml: TXMLDocument; 改为 FXml: IXMLDocument; 其他的不变

6楼: 问题我已经解决了。把FXml改为IXMLDocument。不过我对于接口不是很懂,还想听大虾们讲讲,明天来结束问题。

不过LSUPER,我原来是准备用delphi6带的那个TXMLDocument控件,现在发现不行,改成IXMLDocument接口就可以了。不过不是改这一个地方就可以了,改成接口后创建XML的方法就和原来用控件不一样了。

chenybin,写的是dll。

7楼: 接受答案了.