请问在TObject的子类中申明的TXMLDocument对象怎么实例化 Create参数要求是Tcomponent对象,怎么才能在自定义的类的构造函数中实例化啊?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以CREATE(NIL);不过要自己记得FREE; 一开始已经用过CREATE(NIL)了,用到XMLDocument的方法时还是Access Violation TXMLDocument创建时Create的参数并能为空,应该制定一个父myXMLDocument := TXMLDocument.Create(self);如上面的样式,他不能像许多类实例化时参数为nil,否则出错; TCGeoML2SVG =class(TObject) private xmldocument1:Txmldocument; public procedure test; end;implementationprocedure TCGeoML2SVG.Test();varanode,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; 上面有点错误,重发一下TCGeoML2SVG =class(TObject) private xmldocument1:Txmldocument; public procedure test; end;implementationprocedure TCGeoML2SVG.Test();varanode,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; 上面有点错误,重发一下TCGeoML2SVG =class(TObject) private xmldocument1:Txmldocument; public procedure test; end;implementationprocedure TCGeoML2SVG.Test();varanode,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; http://www.ccw.com.cn/htm/center/prog/02_10_17_4.asp 怎么没有人回答啊?我的简单代码如下我定义的类unit2unit Unit2;interfaceuses 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问题!大虾们请教了!帮帮忙啊!导师看得紧。 现在的问题不是如何使用TXMLDocument控件,而是如何在TObject派生类里面加入TXMLDocument对象并实例化。 我昨天也遇到这个问题,不过没解决。我是这样做的,在你自定义得Create中加入一个TXMLDocument变量,然后在需要用到自定义得类得窗口上加入一个TXMLDocument,作为参数传递给你得自定义类。我是这样做得,没办法,如果你找到解决方法告诉我 [email protected] 不是跟你说了吗,TXMLDocument类实例化是参数不能为nil,你怎么还赋值为空,应该指定对象;constructor TSpreadSheetExchange.Create(var spreadsheet:TSpreadsheet;AOwner:TComponent);begin//类创建时创建电子表格 FSpreadSheet := spreadSheet; xmlDoc := TXMLDocument.Create(AOwner);end; AOwner:TComponent这个TComponent在我自定义的类里面没有TComponent对像啊 delphi中的mediaplayer控件怎么判断对某种视频格式是否支持? 那位大哥知道用delphi视频录制的代码! 请问怎么把图片作为资源加入到资源文件中 IIS7以后对ISAPI的支持有变化? 如何用rave实现这样的打印? delphi的工程(Project)如何改名字呢? 在线等 [讨论]这样的SQL怎么写? 在quickrep中统计本月纪录的合计,然后打印。 我在PUBLIC 中声明过了但在另一个单元也不能引用 怎样用Delphi做串口通讯程序。请给指条路啊!急!v 我这儿有类似速达的表格控件源码,如果有人能帮忙改进的话我就公开源码!(1)
myXMLDocument := TXMLDocument.Create(self);
如上面的样式,他不能像许多类实例化时参数为nil,否则出错;
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;
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;
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;
我定义的类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问题!大虾们请教了!帮帮忙啊!导师看得紧。
我是这样做的,在你自定义得Create中加入一个TXMLDocument变量,然后
在需要用到自定义得类得窗口上加入一个TXMLDocument,作为参数传递给你得自定义类。
我是这样做得,没办法,如果你找到解决方法告诉我 [email protected]
constructor TSpreadSheetExchange.Create(var spreadsheet:TSpreadsheet;AOwner:TComponent);
begin
//类创建时创建电子表格
FSpreadSheet := spreadSheet;
xmlDoc := TXMLDocument.Create(AOwner);
end;
这个TComponent在我自定义的类里面没有TComponent对像啊