"Invalid pointer operation" when free TXMLDocument

49 views Asked by At

I try to use TXMLDocument to load a XML file. However, when I try to free it, I will always get "Invalid pointer operation" exception, as below:

procedure ProcessFile(const SrcFileName: string);
var
  XmlFile: TXMLDocument;
  MainNode, FileNode: IXMLNode;
begin
  CoInitialize(nil);

  XmlFile := TXMLDocument.Create(nil);
  try
    XmlFile.LoadFromFile(SrcFileName);
    //  XmlFile.Active := True;

    MainNode := XmlFile.DocumentElement;
    FileNode := MainNode.ChildNodes['file'];
  finally
    XmlFile.Free;  // Raise exception
    CoUninitialize;
  end;
end;

However, if I remove MainNode and FileNode lines, then there will be OK. Why?

0

There are 0 answers