Paradox / ObjectPal and Microsoft XML Services (MSXML): crashes when calling certain methods

StackOverflow https://stackoverflow.com/questions/14474130

  •  17-01-2022
  •  | 
  •  

Domanda

im using Microsoft XML Core Services (MSXML) to parse and create XML-documents with Paradox 11.0.0.676.

when i call certain methods of the oleAuto-objects, Paradox crashes when reaching the endMethod statement (the code is in the pushButton event of a button). That brought me to the conclusion, that the problem could be the "releasing" of oleAuto-variables. so i´ve put the variable-declarations to the form. if i debug the code, the GPF doesn´t appear at the endMethod of the Button anymore, but still occurs when exiting the program. So i might be right that the problem is where it comes to release variables. Explicit close() orders of the OLE-objects do not solve the problem. Anyone got an idea? I really need that MSXML to work :-( Other MSXML-Methods work very well, like searching XML-files via XPath for specific elements etc. .

here comes the code and the xml-files. the code validates a node of a xml-file against the xml-schema. (code and xml-files are from the microsoft msxml reference, slightly changed and applied to objectpal of course):

ValidateNode.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>

ValidateNode.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 with just a button on it, this is the code from the pushButton Event (quick & dirty code :-)). The code works like it should: the element is shown in a messagebox which tells details about why the element isn´t valid. If i debug the code, Paradox crashes when reaching the endMethod statement. OS is Windows 7 64 Bit, Paradox is Version 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
È stato utile?

Soluzione

i just want to give you a short summary of the problem i had and a fix / workaround for it, since it may help with other activex- and general protection faults issues:

when calling certain methods (my assumption is, that maybe pointers are the problem) of activex-objects, paradox crashes, usually with a general protection fault. in most cases, this happens right before the endmethod-statement is reached. that brought me to the assumption, that the problem might be the "de-referencing" of variables. paradox / windows can´t clear them, or tries to get access to certain spaces of the memory, which is denied by windows. the following code in the pusubutton-event of a button is a good example for that:

method pushButton(var eventInfo Event)
var
    oXD, oXMLElement    oleAuto
endVar

    if NOT oXD.open("Msxml2.DOMDocument.6.0") then
        msgStop("Error", "cant create object")
        return
    endIf

    oXMLElement = oXD.createElement("someElement")
                msgInfo("", oXMLElement.xml)
    oXD.appendChild(oXMLElement)


endMethod

the first time you push the button, the messagebox is displayed, showing the created xml-element. if you now switch from runmode into editmode, run the form and push the button again, paradox crashes: the oleauto variable oXMLElement was still in memory. i spend a lot of time searching for a fix for this problem and i finally got a workaround: before the end of the method, let the oleauto-variable reference another object, the progress-bar e.g.:

if NOT oXMLElement.open("MSComctlLib.ProgCtrl.2") then
    msgStop("Error", "cant create object")
    return
endIf

at least this works for me, with paradox 11, tested on win xp and win 7. any comments to this welcome. :-)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top