先给代码,程序如下:
Function TFileOperation.XMLToList(FileName:string):TList;
var
  temp:TList;
  Root,Parent,Child:IXMLNode;
  Doc:TDocs;
  XML:TXMLDocument;
begin
  temp.Create;
  XML.LoadFromFile(FileName);
  Root:=XML.DocumentElement;
  Parent:=Root.ChildNodes.First;
  while (Parent<>NIL) do
    begin
      Child:=Parent.ChildNodes.First;
      while (Child<>NIL) do
        begin
          Doc.Create;
          Doc.Name:=Child.NodeName;
          Doc.FileName:=Child.Attributes['FileName'];
          Doc.UpdateTime:=Child.Attributes['UpDateTime'];
          Doc.NetPath:=Child.Attributes['NetPath'];
          Doc.FileSize:=Child.Attributes['FileSize'];
          temp.Add(Doc);
          Child:=Child.NextSibling;
        end;
      Parent:=Parent.NextSibling;
    end;
  result:=temp;
end;这样一段程序为什么编译的话编译器显示没有任何问题。但是如果运行的话,DELPHI就会显示“Project Project1.exe raised exception class EClassNotFound with message "class TXMLDocument not found",process stoped,use step or run to continue" ?
我使用的DELPHI 7。希望大大们帮小弟快点解决这个问题,谢谢了

解决方案 »

  1.   

    没有uses XMLDoc 单元吧?
      

  2.   

    //首先,请在你的单元中Uses:XMLDoc和XMLdom和XMLIntf接着是你程序的问题了:
    Function TFileOperation.XMLToList(FileName:string):TList;
    var
      temp:TList;
      Root,Parent,Child:IXMLNode;
      Doc:TDocs;
      XML:TXMLDocument;
    begin
      temp.Create;
      XML.LoadFromFile(FileName); //你的XML变量都没有创建,怎么能用呢
      Root:=XML.DocumentElement;
      Parent:=Root.ChildNodes.First;
      while (Parent<>NIL) do
        begin
          Child:=Parent.ChildNodes.First;
          while (Child<>NIL) do
            begin
              Doc.Create;
              Doc.Name:=Child.NodeName;
              Doc.FileName:=Child.Attributes['FileName'];
              Doc.UpdateTime:=Child.Attributes['UpDateTime'];
              Doc.NetPath:=Child.Attributes['NetPath'];
              Doc.FileSize:=Child.Attributes['FileSize'];
              temp.Add(Doc);
              Child:=Child.NextSibling;
            end;
          Parent:=Parent.NextSibling;
        end;
      result:=temp;
    end;
      

  3.   

    我的USES里有这几项
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, UrlMon, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls, ComCtrls,
      xercesxmldom;然后我在 XML.LoadFromFile(FileName);  前面加了一行语句:XML.Create(nil);
    但是问题依然存在。
    TDOC是我自己定义的。还有就是我编译都通过了,但是就是按F9的时候出现问题
      

  4.   

    我的天,你是不是应该先学一下Delphi的语法,再写程序啊:
    XML.Create(nil);换成
    XML := TXMLDocument.Create(nil);还记得最后一定要XML.Free啊。有创建就要有释放。
      

  5.   

    你的这这一句temp.Create;也改过来吧,改成:
    temp := TList.Create;最后也要调用temp.Free释放掉对象。学一下Delphi语法才是最重要的。
      

  6.   

    多谢大大指点,我会去学DELPHI 语法的.我今年是大一新生,以前在高中学过PASCAL,但是没有时间学DELPHI的语法,也没去买书,都是看网上的原代码学的DELPHI,所以还有很多不懂,现在有时间了可以认真学了.
    但是,我按照您的意见改过来了.
      temp := TList.Create;
      XML:=TXMLDocument.Create(nil);
    还是有我说的哪个问题.这是什么问题呢?
      

  7.   

    你程序一运行就出现这个问题吗,我有时间写一个通用的类发到我的Blog吧。下午再写吧。写后再告诉你。
      

  8.   

    呵呵
    ActiveX类的动态建立
    使用CoInit函数就行的_____________________
    http://lysoft.7u7.net
      

  9.   

    不一定要用MSXML的解析器,我更喜欢用OPenXML原生的类,MSXML在有些机上会出现怪问题。
    还是用OpenXML比较,虽然程序会大很多。
    昨天竟打不开Blog,想发也发不了,气死人了。
    中午再发吧。