Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Do 18.11.10 23:11 
Ich will auf eine XML Datei zugreifen und Schlüssel auslesen.
Bisher habe ich:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var    xml:TXMLDocument;
    Node,Node2:IXMLNode;
begin
  xml:=TXMLDocument.Create(nil);
  xml.LoadFromFile(ParamStr(0)+'a.xml');
  Node:=xml.ChildNodes['metadata'];
  Node2:=Node.ChildNodes['track'];
  //Node:=nil;
  Node:=Node2.ChildNodes['puid-list'];
  ShowMessage(Node.NodeName+':'+Node.Prefix+':'+Node.Text);
  ShowMessage(Node.XML);

Wenn ich dort aber Node was neues zuweisen will (z.b. nil oder den nächsten Wert, darum Node2 als test) dann bekomme ich "ungültige Zeigeroperation".
Was mache ich falsch? Node und Node2 ist <>nil. Werte werden korrekt ausgegeben.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 18.11.10 23:56 
Ich habe den Wrapper schon lange nicht mehr benutzt, der macht ja auch nix anderes als jeden zugriff nochmal extra an die echten Funktionen zu leiten.

Ich benutze die direkte Bibliothek und dann auch sowas wie XPath. Jedenfalls geht es damit sofort so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  xml: DOMDocument60;
  Node, Node2: IXMLDOMNode;
begin
  xml := CoDOMDocument60.Create;
  xml.load(ExtractFilePath(ParamStr(0)) + 'a.xml');
  Node := xml.selectSingleNode('metadata');
  Node2 := Node.selectSingleNode('track');
  //Node:=nil;
  Node := Node2.selectSingleNode('puid-list');
  ShowMessage(Node.NodeName + ':' + Node.Prefix + ':' + Node.Text);
  ShowMessage(Node.XML);
FaTaLGuiLLoTiNe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Fr 19.11.10 00:17 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var xml:TXMLDocument;
    Node,Node2:IXMLNode;
begin
  xml:=TXMLDocument.Create(Application);
  xml.LoadFromFile(ParamStr(0)+'a.xml');
  xml.Active:=True;
  Node:=xml.ChildNodes['metadata'];
  Node2:=Node.ChildNodes['track'];
  //Node:=nil;
  Node:=Node2.ChildNodes['puid-list'];
  ShowMessage(Node.NodeName+':'+Node.Prefix+':'+Node.Text);
  ShowMessage(Node.XML);


Probier' das mal.

_________________
<< FaTaLGuiLLoTiNe >>
Rhinoceroses don't play games!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 19.11.10 06:05 
Ja, das funktioniert. Dass man den Delphi-Wrapper aktiv setzen muss, wusste ich auch nicht.

Ich habe gerade nachgeschaut. Als ich den Wrapper seinerzeit statt des Originals verwendet habe, habe ich die Funktion NewXMLDocument benutzt. Die erzeugt das Objekt und setzt Active direkt auf True, deshalb hab ich davon nichts gemerkt.
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Fr 19.11.10 12:19 
Funktioniert leider nicht. mit dem Active.
Weil:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TXMLDocument.LoadFromFile(const AFileName: DOMString = '');
begin
  SetActive(False);
  if AFileName <> '' then
    FileName := AFileName;
  if FileName = '' then
    XMLDocError(SMissingFileName);
  FXMLData := '';
  SetXMLStrings('');
  SetActive(True);
end;


In welcher Unit ist die NewXMLDocument funktion deklariert?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 19.11.10 12:31 
user profile iconFlamefire hat folgendes geschrieben Zum zitierten Posting springen:
In welcher Unit ist die NewXMLDocument funktion deklariert?
In der XMLDoc, aber bei mir hat der Test mit dem obigen Quelltext dann geklappt. :nixweiss:
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Fr 19.11.10 12:35 
Ok läuft. Hier muss man anscheinend nen Owner übergeben. Das Active ist aber redundant und damit nicht nötig.
Danke

EDIT: Warum eigentlich? Wenn man nen andren Constructor verwendet, dann wird als Owner auch nil genommen. Seltsam.