How to load the XML data into a TTreeView in Delphi in MultiDeviceApplication?

0
Hello, using a procedure that adds to TTreeView the data of an XML file in VCLForms Application works perfectly, whereas in MultiDevice Application

  

Error [dcc32 Error] Unit1.pas (56): E2029 '[' expected but '.' found

relative to AddChild of line: NewTreeNode := TreeView1.Items.AddChild(TreeNode, NodeText); . Remembering that I tested the same code in VCLForms Application and it works perfectly.

  • PROCEDURE:

    procedure TForm1.DomToTree (XmlNode: IXMLNode; TreeNode: TTreeNode);
    var
      I: Integer;
      NewTreeNode: TTreeNode;
      NodeText: string;
      AttrNode: IXMLNode;
    begin
    // skip text nodes and other special cases
    if not (XmlNode.NodeType = ntElement) then
      Exit;
    // add the node itself
    NodeText := XmlNode.NodeName;
    if XmlNode.IsTextElement then
      NodeText := NodeText + ' = ' + XmlNode.NodeValue;
    NewTreeNode := TreeView1.Items.AddChild(TreeNode, NodeText);
    // add attributes
    for I := 0 to xmlNode.AttributeNodes.Count - 1 do
    begin
      AttrNode := xmlNode.AttributeNodes.Nodes[I];
      TreeView1.Items.AddChild(NewTreeNode,'[' + AttrNode.NodeName + ' = "' + AttrNode.Text + '"]');
    end;
    // add each child node
    if XmlNode.HasChildNodes then
    begin
      for I := 0 to xmlNode.ChildNodes.Count - 1 do
        DomToTree (xmlNode.ChildNodes.Nodes [I], NewTreeNode);
      end;
    end;
    
  • WAY OF USE:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      XMLDocument1: IXMLDocument;
    begin
      XMLDocument1 := TXMLDocument.Create(nil);
      XMLDocument1.Active := False;
      XMLDocument1.LoadFromFile('C:\Users\EvertonBruno\Desktop\m.xml');
      XMLDocument1.Active := True;
      Treeview1.Clear;
      DomToTree(XMLDocument1.DocumentElement, nil);
    end;
    
asked by anonymous 17.05.2018 / 21:36

0 answers