Omar Bennani wrote: > --- Rob Kennedy <[EMAIL PROTECTED]> a écrit : >> Does TXMLDocument's owner need to be a data module? Could it be >> something else, like just a plain TComponent? What's special about >> TXMLDocument that it needs to have an owner? > > yes you can use TComponent instead of TDataModule (I try it an d it > works) but I don't know why TXMLDocument must an owner it's another > stupidity from delphi
I asked last night from home, where I only have Delphi 5. Now I'm at work, with Delphi 2005, which has XMLDoc.pas, and I've seen the constructors for TXMLDocument. It has two: constructor Create(AOwner: TComponent); overload; override; constructor Create(const AFileName: DOMString); reintroduce; overload; The second constructor is implemented like this: constructor TXMLDocument.Create(const AFileName: DOMString); begin inherited Create(nil); FFileName := AFileName; end; The component does not appear to require an owner. Supposedly, in what way does the component not work otherwise? If the component has an owner, then its behavior is modified slightly. If it has an owner and its reference count reaches zero, it will not destroy itself the way most interfaced objects would. If the component has an owner, then when it gets destroyed with a reference count greater than one, it will call ClearDocumentRef on its document node, instructing the node and all its children to sever their references to the TXMLDocument. Failure to do this would lead to exceptions later, when the document node eventually gets destroyed and tries to decrement the reference count of the TXMLDocument, which has already been destroyed. Both of these are to mitigate problems that occur when mixing interface references with object references, but that's something you should never do anyway. There's really no reason for TXMLDocument to descend from TComponent at all. It's only designed that way to facilitate RAD drag-and-drop development; I wonder why TStringList doesn't also descend from TComponent. -- Rob _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

