[如何理解]Delphi 7處理XML方式的程式碼 |
缺席
|
aAlan
一般會員 ![]() ![]() 發表:38 回覆:24 積分:12 註冊:2004-07-23 發送簡訊給我 |
最近在讀以下程式碼,是有關於delphi 7如何處理XML文件,
當中發現了很多陌生的語法,程式看的很痛苦!
有沒有前輩願意用連載的方式逐行舉例說明以下程式碼的意義
來引導對使用delphi 7 處理XML的初學者建立基礎呢? 看不懂以下程式碼粗體部分到底有什麼作用?懵懵懂懂的... {***************************************************************}
{ }
{ Delphi XML Data Binding }
{ }
{ Generated on: 2001/10/8 下午 09:47:20 }
{ Generated from: C:\Paul\Delphi6\Prog\Charp19\xml1.xml }
{ Settings stored in: C:\Paul\Delphi6\Prog\Charp19\xml1.xdb }
{ }
{***************************************************************}
unit Unit19_22; interface uses xmldom, XMLDoc, XMLIntf; type { Forward Decls } IXMLXmlType = interface;
IXMLTbType = interface; { IXMLXmlType } IXMLXmlType = interface(IXMLNodeCollection)
['{31A062AA-0EA4-4E59-80C4-EA04924D3C48}']
{ Property Accessors }
function Get_Tb(Index: Integer): IXMLTbType;
{ Methods & Properties }
function Add: IXMLTbType;
function Insert(const Index: Integer): IXMLTbType;
property Tb[Index: Integer]: IXMLTbType read Get_Tb; default;
end; { IXMLTbType } IXMLTbType = interface(IXMLNode)
['{CFA845D2-FED5-4710-A938-59558A36DCC6}']
{ Property Accessors }
function Get_Color: WideString;
function Get_F1: WideString;
function Get_F3: WideString;
function Get_F2: WideString;
procedure Set_Color(Value: WideString);
procedure Set_F1(Value: WideString);
procedure Set_F3(Value: WideString);
procedure Set_F2(Value: WideString);
{ Methods & Properties }
property Color: WideString read Get_Color write Set_Color;
property F1: WideString read Get_F1 write Set_F1;
property F3: WideString read Get_F3 write Set_F3;
property F2: WideString read Get_F2 write Set_F2;
end; { Forward Decls } TXMLXmlType = class;
TXMLTbType = class; { TXMLXmlType } TXMLXmlType = class(TXMLNodeCollection, IXMLXmlType)
protected
{ IXMLXmlType }
function Get_Tb(Index: Integer): IXMLTbType;
function Add: IXMLTbType;
function Insert(const Index: Integer): IXMLTbType;
public
procedure AfterConstruction; override;
end; { TXMLTbType } TXMLTbType = class(TXMLNode, IXMLTbType)
protected
{ IXMLTbType }
function Get_Color: WideString;
function Get_F1: WideString;
function Get_F3: WideString;
function Get_F2: WideString;
procedure Set_Color(Value: WideString);
procedure Set_F1(Value: WideString);
procedure Set_F3(Value: WideString);
procedure Set_F2(Value: WideString);
end; { Global Functions } function Getxml(Doc: IXMLDocument): IXMLXmlType;
function Loadxml(const FileName: WideString): IXMLXmlType;
function Newxml: IXMLXmlType; implementation { Global Functions } function Getxml(Doc: IXMLDocument): IXMLXmlType;
begin
Result := Doc.GetDocBinding('xml', TXMLXmlType) as IXMLXmlType;
end;
function Loadxml(const FileName: WideString): IXMLXmlType;
begin
Result := LoadXMLDocument(FileName).GetDocBinding('xml', TXMLXmlType) as IXMLXmlType;
end; function Newxml: IXMLXmlType;
begin
Result := NewXMLDocument.GetDocBinding('xml', TXMLXmlType) as IXMLXmlType;
end; { TXMLXmlType } procedure TXMLXmlType.AfterConstruction;
begin
RegisterChildNode('tb', TXMLTbType);
ItemTag := 'tb';
ItemInterface := IXMLTbType;
inherited;
end; function TXMLXmlType.Get_Tb(Index: Integer): IXMLTbType;
begin
Result := List[Index] as IXMLTbType;
end; function TXMLXmlType.Add: IXMLTbType;
begin
Result := AddItem(-1) as IXMLTbType;
end; function TXMLXmlType.Insert(const Index: Integer): IXMLTbType;
begin
Result := AddItem(Index) as IXMLTbType;
end; { TXMLTbType } function TXMLTbType.Get_Color: WideString;
begin
Result := AttributeNodes['color'].Text;
end; procedure TXMLTbType.Set_Color(Value: WideString);
begin
SetAttribute('color', Value);
end; function TXMLTbType.Get_F1: WideString;
begin
Result := ChildNodes['f1'].Text;
end; procedure TXMLTbType.Set_F1(Value: WideString);
begin
ChildNodes['f1'].NodeValue := Value;
end; function TXMLTbType.Get_F3: WideString;
begin
Result := ChildNodes['f3'].Text;
end; procedure TXMLTbType.Set_F3(Value: WideString);
begin
ChildNodes['f3'].NodeValue := Value;
end; function TXMLTbType.Get_F2: WideString;
begin
Result := ChildNodes['f2'].Text;
end; procedure TXMLTbType.Set_F2(Value: WideString);
begin
ChildNodes['f2'].NodeValue := Value;
end; end.
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |