⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 email.pas

📁 用Delphi对XML进行增删改操作示例
💻 PAS
字号:

{*****************************************************************************}
{                                                                             }
{                              XML Data Binding                               }
{                                                                             }
{         Generated on: 2007-12-8 10:16:23                                    }
{       Generated from: D:\Program Files\Borland\Delphi7\Projects\email.xml   }
{   Settings stored in: D:\Program Files\Borland\Delphi7\Projects\email.xdb   }
{                                                                             }
{*****************************************************************************}

unit Email;

interface

uses xmldom, XMLDoc, XMLIntf;

type

{ Forward Decls }

  IXMLNoteType = interface;
  IXMLFromType = interface;
  IXMLContactType = interface;
  IXMLToType = interface;

{ IXMLNoteType }

  IXMLNoteType = interface(IXMLNode)
    ['{CB928579-5602-49ED-AC0B-0C2677C63961}']
    { Property Accessors }
    function Get_Heading: WideString;
    function Get_From: IXMLFromType;
    function Get_To_: IXMLToType;
    function Get_Body: WideString;
    procedure Set_Heading(Value: WideString);
    procedure Set_Body(Value: WideString);
    { Methods & Properties }
    property Heading: WideString read Get_Heading write Set_Heading;
    property From: IXMLFromType read Get_From;
    property To_: IXMLToType read Get_To_;
    property Body: WideString read Get_Body write Set_Body;
  end;

{ IXMLFromType }

  IXMLFromType = interface(IXMLNodeCollection)
    ['{1D07CAE1-5579-4A3F-AFC4-AAA5FEE09AD0}']
    { Property Accessors }
    function Get_Contact(Index: Integer): IXMLContactType;
    { Methods & Properties }
    function Add: IXMLContactType;
    function Insert(const Index: Integer): IXMLContactType;
    property Contact[Index: Integer]: IXMLContactType read Get_Contact; default;
  end;

{ IXMLContactType }

  IXMLContactType = interface(IXMLNode)
    ['{56034793-5317-4E63-AEBA-707C6D1392F9}']
    { Property Accessors }
    function Get_Name: WideString;
    function Get_Email: WideString;
    procedure Set_Name(Value: WideString);
    procedure Set_Email(Value: WideString);
    { Methods & Properties }
    property Name: WideString read Get_Name write Set_Name;
    property Email: WideString read Get_Email write Set_Email;
  end;

{ IXMLToType }

  IXMLToType = interface(IXMLNodeCollection)
    ['{5748682B-07F0-4A6D-B240-84267FFEF412}']
    { Property Accessors }
    function Get_Contact(Index: Integer): IXMLContactType;
    { Methods & Properties }
    function Add: IXMLContactType;
    function Insert(const Index: Integer): IXMLContactType;
    property Contact[Index: Integer]: IXMLContactType read Get_Contact; default;
  end;

{ Forward Decls }

  TXMLNoteType = class;
  TXMLFromType = class;
  TXMLContactType = class;
  TXMLToType = class;

{ TXMLNoteType }

  TXMLNoteType = class(TXMLNode, IXMLNoteType)
  protected
    { IXMLNoteType }
    function Get_Heading: WideString;
    function Get_From: IXMLFromType;
    function Get_To_: IXMLToType;
    function Get_Body: WideString;
    procedure Set_Heading(Value: WideString);
    procedure Set_Body(Value: WideString);
  public
    procedure AfterConstruction; override;
  end;

{ TXMLFromType }

  TXMLFromType = class(TXMLNodeCollection, IXMLFromType)
  protected
    { IXMLFromType }
    function Get_Contact(Index: Integer): IXMLContactType;
    function Add: IXMLContactType;
    function Insert(const Index: Integer): IXMLContactType;
  public
    procedure AfterConstruction; override;
  end;

{ TXMLContactType }

  TXMLContactType = class(TXMLNode, IXMLContactType)
  protected
    { IXMLContactType }
    function Get_Name: WideString;
    function Get_Email: WideString;
    procedure Set_Name(Value: WideString);
    procedure Set_Email(Value: WideString);
  end;

{ TXMLToType }

  TXMLToType = class(TXMLNodeCollection, IXMLToType)
  protected
    { IXMLToType }
    function Get_Contact(Index: Integer): IXMLContactType;
    function Add: IXMLContactType;
    function Insert(const Index: Integer): IXMLContactType;
  public
    procedure AfterConstruction; override;
  end;

{ Global Functions }

function GetNote(Doc: IXMLDocument): IXMLNoteType;
function LoadNote(const FileName: WideString): IXMLNoteType;
function NewNote: IXMLNoteType;

const
  TargetNamespace = '';

implementation

{ Global Functions }

function GetNote(Doc: IXMLDocument): IXMLNoteType;
begin
  Result := Doc.GetDocBinding('Note', TXMLNoteType, TargetNamespace) as IXMLNoteType;
end;

function LoadNote(const FileName: WideString): IXMLNoteType;
begin
  Result := LoadXMLDocument(FileName).GetDocBinding('Note', TXMLNoteType, TargetNamespace) as IXMLNoteType;
end;

function NewNote: IXMLNoteType;
begin
  Result := NewXMLDocument.GetDocBinding('Note', TXMLNoteType, TargetNamespace) as IXMLNoteType;
end;

{ TXMLNoteType }

procedure TXMLNoteType.AfterConstruction;
begin
  RegisterChildNode('From', TXMLFromType);
  RegisterChildNode('To', TXMLToType);
  inherited;
end;

function TXMLNoteType.Get_Heading: WideString;
begin
  Result := ChildNodes['Heading'].Text;
end;

procedure TXMLNoteType.Set_Heading(Value: WideString);
begin
  ChildNodes['Heading'].NodeValue := Value;
end;

function TXMLNoteType.Get_From: IXMLFromType;
begin
  Result := ChildNodes['From'] as IXMLFromType;
end;

function TXMLNoteType.Get_To_: IXMLToType;
begin
  Result := ChildNodes['To'] as IXMLToType;
end;

function TXMLNoteType.Get_Body: WideString;
begin
  Result := ChildNodes['Body'].Text;
end;

procedure TXMLNoteType.Set_Body(Value: WideString);
begin
  ChildNodes['Body'].NodeValue := Value;
end;

{ TXMLFromType }

procedure TXMLFromType.AfterConstruction;
begin
  RegisterChildNode('Contact', TXMLContactType);
  ItemTag := 'Contact';
  ItemInterface := IXMLContactType;
  inherited;
end;

function TXMLFromType.Get_Contact(Index: Integer): IXMLContactType;
begin
  Result := List[Index] as IXMLContactType;
end;

function TXMLFromType.Add: IXMLContactType;
begin
  Result := AddItem(-1) as IXMLContactType;
end;

function TXMLFromType.Insert(const Index: Integer): IXMLContactType;
begin
  Result := AddItem(Index) as IXMLContactType;
end;

{ TXMLContactType }

function TXMLContactType.Get_Name: WideString;
begin
  Result := ChildNodes['Name'].Text;
end;

procedure TXMLContactType.Set_Name(Value: WideString);
begin
  ChildNodes['Name'].NodeValue := Value;
end;

function TXMLContactType.Get_Email: WideString;
begin
  Result := ChildNodes['Email'].Text;
end;

procedure TXMLContactType.Set_Email(Value: WideString);
begin
  ChildNodes['Email'].NodeValue := Value;
end;

{ TXMLToType }

procedure TXMLToType.AfterConstruction;
begin
  RegisterChildNode('Contact', TXMLContactType);
  ItemTag := 'Contact';
  ItemInterface := IXMLContactType;
  inherited;
end;

function TXMLToType.Get_Contact(Index: Integer): IXMLContactType;
begin
  Result := List[Index] as IXMLContactType;
end;

function TXMLToType.Add: IXMLContactType;
begin
  Result := AddItem(-1) as IXMLContactType;
end;

function TXMLToType.Insert(const Index: Integer): IXMLContactType;
begin
  Result := AddItem(Index) as IXMLContactType;
end;

end. 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -