var newXml: TXMLDocument; // instead of "iXMLDocument"
newXml := TXMLDocument.Create(nil);
And now please read the documentation about creating the document with or without the owner.
- http://docwiki.embarcadero.com/Libraries/XE4/en/Xml.XMLDoc.TXMLDocument
- http://docwiki.embarcadero.com/Libraries/XE4/en/Xml.XMLDoc.TXMLDocument.Create
You should either create it as plain object, that lives until you .Free
it - but then it should have an owner.
Or you should use reference-counted interfaces and ALWAYS keep at least one variable alive that links to the document.
- http://en.wikipedia.org/wiki/Reference_counting
- http://docwiki.embarcadero.com/RADStudio/XE4/en/Implementing_IInterface
The latter approach shown in... again in the documentaton:
- http://docwiki.embarcadero.com/CodeSamples/en/TXMLDocument_use_case_(Delphi)
- http://docwiki.embarcadero.com/Libraries/XE4/en/Xml.XMLIntf.IXMLDocument
Read the documentation
- http://docwiki.embarcadero.com/Libraries/XE2/en/System.IUnknown
- http://docwiki.embarcadero.com/RADStudio/XE4/en/Object_Interfaces
- http://docwiki.embarcadero.com/RADStudio/XE4/en/Interface_References
PS.