我看不到你的功能和类型
RGearing : IXMLracegearingType;
RGearing :=Getracegearing(XMLDocument1);
所以我只能用下面的代码来测试它。
浏览代码并根据您的需要对其进行自定义。
unit xmlCombo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
cbManufac: TComboBox;
cbModel: TComboBox;
procedure getManufac;
procedure getModel(const ManufacVal:string);
procedure FormActivate(Sender: TObject);
procedure cbManufacClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses MSXML,ActiveX,ComObj;
const
XMLTestStr =
'<?xml version="1.0" encoding="UTF-8"?>'+
'<gearing>'+
' <car>'+
' <id>1</id>'+
' <manufacturer>Ford</manufacturer>'+
' <model>Test 1</model>'+
' <year></year>'+
' </car>'+
' <car>'+
' <id>2</id>'+
' <manufacturer>Ford</manufacturer>'+
' <model>Test 2</model>'+
' <year></year>'+
' </car>'+
' <car>'+
' <id>3</id>'+
' <manufacturer>Honda</manufacturer>'+
' <model>Test 1</model>'+
' <year></year>'+
' </car>'+
' <settings>'+
' <form_height></form_height>'+
' <form_width></form_width>'+
' </settings>'+
'</gearing>';
var
varManufac : string;
RGearing : IXMLDOMDocument;
procedure TForm1.cbManufacClick(Sender: TObject);
begin
getModel(cbManufac.Items[cbManufac.ItemIndex]);
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
RGearing:=CoDOMDocument.Create;
RGearing.loadXML(XmlTestStr);
getManufac;
end;
procedure TForm1.getModel(const ManufacVal:string);
Var
XMLDOMNodeL : IXMLDOMNodeList;
ChildST : String;
ChildN,BNode : IXMLDOMNode;
i : Integer;
begin
cbModel.Items.Clear;
cbModel.Text:='';
XMLDOMNodeL:=RGearing.getElementsByTagName('car');
for i := 0 to XMLDOMNodeL.length-1 do
begin
ChildN:=XMLDOMNodeL[i].selectSingleNode('manufacturer');
if ChildN.text=ManufacVal then begin
BNode:=XMLDOMNodeL[i].selectSingleNode('model');
ChildST:=BNode.text;
if cbModel.Items.IndexOf(ChildST) = -1 then cbModel.Items.Add(ChildST);
end;
end;
end;
procedure TForm1.getManufac;
Var
XMLDOMNodeList : IXMLDOMNodeList;
ChildST : string;
i : Integer;
begin
cbManufac.Items.Clear;
cbManufac.Text:='';
// Populate Manufacturer combobox
XMLDOMNodeList:=RGearing.getElementsByTagName('manufacturer');
for i := 0 to XMLDOMNodeList.length-1 do
begin
ChildST:=XMLDOMNodeList[i].text;
if cbManufac.Items.IndexOf(ChildST) = -1 then cbManufac.Items.Add(ChildST);
if cbManufac.Items.Count = 1 then begin
cbManufac.Text:=ChildST;
getModel(ChildST);
end;
end;
end;
end.
从文件加载 xml。
if RGearing.Load('File.xml') then
[...]
else
ShowMessage('Could not load file : File.xml');
end;
我希望这有帮助。