本帖最后由 r9000_com 于 2011-05-27 08:55:33 编辑

解决方案 »

  1.   

    调试啊,肯定是那个对象为nil
      

  2.   


    function xmltohtml(xmlsource:string):string;
    var
    Root,n1,n2,data:IXMLNode;
    xdoc:TXMLDocument;
    begin
    xdoc := TXMLDocument.Create(nil);
    xdoc.LoadFromXML(xmlsource);
      xdoc.Active := true;
      Root := xdoc.DocumentElement;
      n1:=Root.ChildNodes[0];
      n2:=n1.ChildNodes.First;
      showmessage(n2.text);
    end;---------上面这段代码提示:Invalid pointer operation
    如果把它放到,onclick事件中,却是一点问题都没有,何解啊?procedure TForm1.Button1Click(Sender: TObject);
    var
    Root,n1,n2,data:IXMLNode;
    xdoc:TXMLDocument;
    begin
    xdoc := TXMLDocument.Create(nil);
    xdoc.LoadFromXML(xmlsource);
      xdoc.Active := true;
      Root := xdoc.DocumentElement;
      n1:=Root.ChildNodes[0];
      n2:=n1.ChildNodes.First;
      showmessage(n2.text);
    end;
    -------这一段就一点问题都没有
      

  3.   


    试了,用loadfromfile('c:\resl.xml'),一样的出错就是不能放函数中去,奇怪
      

  4.   

    function xmltohtml(xmlsource:string):string;
    var
    Root,n1,n2,data:IXMLNode;
    xdoc:TXMLDocument; -----------> IXMLDocument;
    begin
    xdoc := TXMLDocument.Create(nil);
    xdoc.LoadFromXML(xmlsource);
      xdoc.Active := true;
      Root := xdoc.DocumentElement;
      n1:=Root.ChildNodes[0];
      n2:=n1.ChildNodes.First;
      showmessage(n2.text);
    end;要引用这4个单元: xmldom, XMLIntf, msxmldom, XMLDoc
      

  5.   

    搞定了,谢谢大家热心帮忙.
    function xmltohtml(xmlsource:string):string;
    var
    Root,n1,n2,data:IXMLNode;
    xdoc:IXMLDocument;
    begin
    xdoc := NewXMLDocument(nil);
    CoInitialize(nil);
    xdoc.LoadFromXML(xmlsource);
    Root := xdoc.DocumentElement;
    n1:=Root.ChildNodes[0];
    n2:=n1.ChildNodes.First;
    end;
     xdoc:=nil;
     CoUninitialize();