我使用 Microsoft XML Core Services (MSXML) 来解析和创建带有 Paradox 11.0.0.676 的 XML 文档。
当我调用 oleAuto 对象的某些方法时,Paradox 在到达 endMethod 语句时崩溃(代码在按钮的 pushButton 事件中)。这使我得出结论,问题可能是 oleAuto 变量的“释放”。所以我已经把变量声明放到了表单中。如果我调试代码,GPF 不再出现在按钮的 endMethod 中,但在退出程序时仍然会出现。所以我可能是对的,问题在于释放变量。OLE 对象的显式 close() 命令不能解决问题。有人有想法吗?我真的需要 MSXML 工作 :-( 其他 MSXML 方法工作得很好,比如通过 XPath 搜索 XML 文件以查找特定元素等。。
这里是代码和 xml 文件。该代码根据 xml 模式验证 xml 文件的节点。(代码和 xml 文件来自 microsoft msxml 参考,稍作改动并应用于 objectpal):
验证节点.xml
<?xml version="1.0"?>
<x:books xmlns:x="urn:books">
<book id="bk001">
<author>Hightower, Kim</author>
<title>The First Book</title>
<genre>Fiction</genre>
<price>44.95</price>
<pub_date>2000-10-01</pub_date>
<review>An amazing story of nothing.</review>
</book>
<book id="bk003">
<author>Nagata, Suanne</author>
<title>Becoming Somebody</title>
<genre>Biography</genre>
<review>A masterpiece of the fine art of gossiping.</review>
</book>
</x:books>
验证节点.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:books"
xmlns:bks="urn:books">
<xsd:element name="books" type="bks:BooksForm"/>
<xsd:complexType name="BooksForm">
<xsd:sequence>
<xsd:element name="book"
type="bks:BookForm"
minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BookForm">
<xsd:sequence>
<xsd:element name="author" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="genre" type="xsd:string"/>
<xsd:element name="price" type="xsd:float" />
<xsd:element name="pub_date" type="xsd:date" />
<xsd:element name="review" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
ObjectPal-Code:Paradox-Form,上面只有一个按钮,这是 pushButton 事件的代码(快速和脏代码:-))。代码按其应有的方式工作:元素显示在一个消息框中,该消息框告诉您有关该元素无效的原因的详细信息。如果我调试代码,Paradox 在到达 endMethod 语句时会崩溃。操作系统是 Windows 7 64 位,Paradox 是版本 11.0.0.676。
method pushButton(var eventInfo Event)
var
xd, xs, er, nlist, node oleAuto
err oleAuto
endVar
if NOT xd.open("Msxml2.DOMDocument.6.0") then
msgStop("Error", "Error")
return
endIf
if NOT xs.open("Msxml2.XMLSchemaCache.6.0") then
msgStop("Error", "Error")
return
endIf
xs.add("urn:books", "C:\\LZE\\MSXML\\validateNode.xsd")
try
xd^schemas = xs
xd^async = false
xd^validateOnParse = false
xd^load("C:\\LZE\\MSXML\\validateNode.xml")
err = xd^validate()
nList = xd^selectNodes("//book")
node = nList^item(1)
msgInfo("", node.xml)
err = xd^validateNode(node)
msgInfo("", err.reason)
onFail
msgStop("!!!", "!!!")
endTry
try
if xd.isAssigned() then
xd.close()
endIf
if xs.isAssigned() then
xs.close()
endIf
if nList.isAssigned() then
nList.close()
endIf
if err.isAssigned() then
err.close()
endIf
onFail
msgStop("!!!", "!!!")
endTry