Re: TXMLDocument and TTreeView



Cafetorium <phil@xxxxxxxxxxxxxxxx> wrote in news:1185459002.704130.267600
@l70g2000hse.googlegroups.com:

I've been tinkering with the idea of using a TTreeView to display the
contents of an XML file.

I can parse the TXMLDocument and add nodes to the tree with no
problems, but it would be really useful if I could attach each node to
the Data property so that I can access it immediately.

The Data porperty is a (System.)Pointer, but the object I use when
traversing the XML Document is a (XMLIntf.)IXMLNode, and I can't work
out how to use these two together.

I tried
tn.Data := addr(iNode);
which worked ok.

Then in my TreeView OnClick method, I want to get the XML node back
again by accessing the Data object, but I can't work out how to do it.

iNode := tn.Data^;
doesn't work, and neither does
iNode := tn.Data^ as IXMLNode;

I guess this is something to do with the fact that IXMLNode is an
interface and I don't really understand how it works.

Can anyone enlighten me, please?

Phil

IXMLNode(tn.Data) := iNode;

iNode := IXMLNode(tn.Data); // or
iNode := IInterface(tn.Data) as IXMLNode; // if the QI is needed

And, when the treenode is destroyed, don't forget to

IXMLNode(tn.Data) := nil;

Casting the treenode in the above cases will cause the compiler to
generate the appropriate interface reference-counting code which will not
happen if you take the other alternative of casting the interface to a
pointer.

You may be better off using a custom tree node type (provision for which
was added in Delphi 6) with an explicit IXMLNode property.
.



Relevant Pages

  • Re: developing for something that isnt there..
    ... xml was chosen becouse well. ... creating a tree model of javabeans was my insisting becouse i didnt' ... had a complelty differnt strucutre and style of interface, ... and interface to send messages about them the classes ...
    (comp.lang.java.programmer)
  • Re: developing for something that isnt there..
    ... i've been taksed to create a framework that would read a complex xml ... problem that java bean tree has not been built yet. ... i do have a concept of what to pull from the xml, ... and interface to send messages about them the classes ...
    (comp.lang.java.programmer)
  • Re: developing for something that isnt there..
    ... problem that java bean tree has not been built yet. ... i do have a concept of what to pull from the xml, ... and interface to send messages about them the classes ...
    (comp.lang.java.programmer)
  • Re: TXMLDocument and TTreeView
    ... when traversing the XML Document is a IXMLNode, ... interface and I don't really understand how it works. ... which was added in Delphi 6) with an explicit IXMLNode property. ... I should have checked that the Data property of a TTreeNode was ...
    (alt.comp.lang.borland-delphi)
  • developing for something that isnt there..
    ... problem that java bean tree has not been built yet. ... i do have a concept of what to pull from the xml, ... and interface to send messages about them the classes ...
    (comp.lang.java.programmer)