Create参数要求是Tcomponent对象,怎么才能在自定义的类的构造函数中实例化啊?谢谢!

解决方案 »

  1.   

    可以CREATE(NIL);不过要自己记得FREE;
      

  2.   

    一开始已经用过CREATE(NIL)了,用到XMLDocument的方法时还是Access Violation
      

  3.   

    TXMLDocument创建时Create的参数并能为空,应该制定一个父
    myXMLDocument := TXMLDocument.Create(self);
    如上面的样式,他不能像许多类实例化时参数为nil,否则出错;
      

  4.   

    TCGeoML2SVG =class(TObject)
      private
      xmldocument1:Txmldocument;
      public
      procedure test; 
    end;implementation
    procedure TCGeoML2SVG.Test();
    var
    anode,anode1:Ixmlnode;
    begin
    //xmldocument1:=TCGeoML2SVG.create(self);(请问各位大虾xmldocument1如何在这里实例化)
    xmldocument1.XML.Add('<?xml version="1.0" encoding="gb2312"?>');
    xmldocument1.XML.Add('<CgeoML/>');
    xmldocument1.Active:=true;
    anode:=xmldocument1.DocumentElement.AddChild('CGeoMLPointCollection');
    anode1:=anode.addchild('CGeoMLLonePoint');
    xmldocument1.SaveToFile('e:\slpp.xml');
    end;
      

  5.   

    上面有点错误,重发一下TCGeoML2SVG =class(TObject)
      private
      xmldocument1:Txmldocument;
      public
      procedure test; 
    end;implementation
    procedure TCGeoML2SVG.Test();
    var
    anode,anode1:Ixmlnode;
    begin
    //xmldocument1:=xmldocument1.create(self);(请问各位大虾xmldocument1如何在这里实例化)
    xmldocument1.XML.Add('<?xml version="1.0" encoding="gb2312"?>');
    xmldocument1.XML.Add('<CgeoML/>');
    xmldocument1.Active:=true;
    anode:=xmldocument1.DocumentElement.AddChild('CGeoMLPointCollection');
    anode1:=anode.addchild('CGeoMLLonePoint');
    xmldocument1.SaveToFile('e:\slpp.xml');
    end;
      

  6.   

    上面有点错误,重发一下TCGeoML2SVG =class(TObject)
      private
      xmldocument1:Txmldocument;
      public
      procedure test; 
    end;implementation
    procedure TCGeoML2SVG.Test();
    var
    anode,anode1:Ixmlnode;
    begin
    //xmldocument1:=TXmldocument.create(self);(请问各位大虾xmldocument1如何在这里实例化)
    xmldocument1.XML.Add('<?xml version="1.0" encoding="gb2312"?>');
    xmldocument1.XML.Add('<CgeoML/>');
    xmldocument1.Active:=true;
    anode:=xmldocument1.DocumentElement.AddChild('CGeoMLPointCollection');
    anode1:=anode.addchild('CGeoMLLonePoint');
    xmldocument1.SaveToFile('e:\slpp.xml');
    end;
      

  7.   

    http://www.ccw.com.cn/htm/center/prog/02_10_17_4.asp
      

  8.   

    怎么没有人回答啊?我的简单代码如下
    我定义的类unit2
    unit Unit2;interface
    uses SysUtils,XMLDoc;
    type
      MyClass = class(TObject)  constructor Create(EName:Ansistring);
      procedure GetDoc(fname:ansistring);  private    { Private declarations }
      public
        Name:Ansistring;{ Public declarations }
        XMLDoc:TXMLDocument;
      end;
    implementation{ MyClass }constructor MyClass.Create(EName: Ansistring);
    begin
      //inherited Create;
      self.Name:=EName;
      XMLDoc:=TXMLDocument.Create(nil);end;procedure MyClass.GetDoc(fname: ansistring);
    begin
      self.XMLDoc.LoadFromFile(fname);
    end;end.在窗体事件中的代码
    procedure TForm1.Button1Click(Sender: TObject);
    var
      cls:MyClass;begin
      cls.Create('brune');
      showmessage(cls.Name);
      cls.GetDoc('skin.xml');
    end;现在的问题就是运行到cls.GetDoc('skin.xml')语句就出现头疼的AV问题!大虾们请教了!帮帮忙啊!导师看得紧。
      

  9.   

    现在的问题不是如何使用TXMLDocument控件,而是如何在TObject派生类里面加入TXMLDocument对象并实例化。
      

  10.   

    我昨天也遇到这个问题,不过没解决。
    我是这样做的,在你自定义得Create中加入一个TXMLDocument变量,然后
    在需要用到自定义得类得窗口上加入一个TXMLDocument,作为参数传递给你得自定义类。
    我是这样做得,没办法,如果你找到解决方法告诉我 [email protected]
      

  11.   

    不是跟你说了吗,TXMLDocument类实例化是参数不能为nil,你怎么还赋值为空,应该指定对象;
    constructor TSpreadSheetExchange.Create(var spreadsheet:TSpreadsheet;AOwner:TComponent);
    begin
    //类创建时创建电子表格
        FSpreadSheet := spreadSheet;
        xmlDoc := TXMLDocument.Create(AOwner);
    end;
      

  12.   

    AOwner:TComponent
    这个TComponent在我自定义的类里面没有TComponent对像啊