在delphi中使用xml文档有两种方法

2016-02-19 19:58 4 1 收藏

想不想get新技能酷炫一下,今天图老师小编就跟大家分享个简单的在delphi中使用xml文档有两种方法教程,一起来看看吧!超容易上手~

【 tulaoshi.com - 编程语言 】

在delphi中使用xml文档有两种方法
  使用xml broker, 是delphi 内置的。例:
  unit ShowXML;
  interface
  uses Classes  HTTPApp  Db  DbClient  Midas 
    XMLBrokr  WebComp  MidItems;
  type
    TCustomShowXMLButton = class(TXMLButton  IScriptComponent)
    protected
      XMLMethodName: string;
      { IScriptComponent }
      procedure AddElements(AddIntf: IAddScriptElements);
      function GetSubComponents: TObject;
      { IWebContent implementation }
      function ImplContent(Options: TWebContentOptions;
        ParentLayout: TLayout): string; override;
    end;
    TShowXMLButton = class(TCustomShowXMLButton)
    public
      constructor Create(AOwner: TComponent); override;
    published
      property Custom;
      property Style;
      property StyleRule;
      property Caption;
      property XMLBroker;
      property XMLUseParent;
    end;
    TShowDeltaButton = class(TCustomShowXMLButton)
    public
      constructor Create(AOwner: TComponent); override;
    published
      property Custom;
      property Style;
      property StyleRule;
      property Caption;
      property XMLBroker;
      property XMLUseParent;
    end;
  implementation
  uses sysutils  MidProd;
  resourcestring 
    sShowXML = 'Show XML';
    sShowDelta = 'Show Delta';
  procedure TCustomShowXMLButton.AddElements(
    AddIntf: IAddScriptElements);
  begin
    AddIntf.AddIncludeFile('xmlshow.js');
  end;
  function TCustomShowXMLButton.GetSubComponents: TObject;
  begin
    Result := nil;
  end;
  function TCustomShowXMLButton.ImplContent(Options: TWebContentOptions;
    ParentLayout: TLayout): string;
  var
    Attrs: string;
    Intf: ILayoutWebContent;
    FormVarName: string;
    RowSetVarName: string;
  begin
    AddQuotedAttrib(Attrs  'NAME'  Name);
    AddQuotedAttrib(Attrs  'STYLE'  Style);
    AddQuotedAttrib(Attrs  'CLASS'  StyleRule);
    AddQuotedAttrib(Attrs  'VALUE'  Self.Caption);
    AddCustomAttrib(Attrs  Custom);
    if Assigned(XMLData.XMLBroker) then
    begin
      FormVarName := XMLData.XMLBroker.SubmitFormVarName;
      RowSetVarName := XMLData.XMLBroker.RowSetVarName(nil);  // Row row set var name
    end;
    if not (coNoScript in Options.Flags) then
      Result :=
        Format(''#13#10 
          [Attrs  RowSetVarName  XMLMethodName  sXMLReadyVar])
    else
      Result :=
        Format(''#13#10 
          [Attrs]);
    if Assigned(ParentLayout) and ParentLayout.GetInterface(ILayoutWebContent  Intf) then
      Result := Intf.LayoutButton(Result  GetLayoutAttributes);
  end;
  { TShowXMLButton }
  constructor TShowXMLButton.Create(AOwner: TComponent);
  begin
    inherited;
    DefaultCaption := sShowXML;
    XMLMethodName := 'root';
  end;
  { TShowDeltaButton }
  constructor TShowDeltaButton.Create(AOwner: TComponent);
  begin
    inherited;
    DefaultCaption := sShowDelta;
    XMLMethodName := 'getDelta()';
  end;
  另一种方法使用msxml.dll 如下:
  ....
  ....
  procedure TDHEDForm.OpenBtnClick(Sender: TObject);
  var
   pVIn : OleVariant;
   Prompt : OleVariant;
  begin
    pVIn := '';
    Prompt := True;
    DHtmlEdit1.LoadDocument(pVIn  Prompt);
  end;
  procedure TDHEDForm.SaveBtnClick(Sender: TObject);
  var
    vo  vb : OleVariant;
  begin
    vo := DHTMLEdit1.CurrentDocumentPath;
    if (vo '') then 
    begin
       vb := false;
    end 
    else 
    begin
       vo := '';
       vb := true;
    end;                                          
    DHTMLEdit1.SaveDocument(vo  vb);
  end;
  procedure TDHEDForm.SaveAsClick(Sender: TObject);
  var
    vo  vb : OleVariant;
  begin
    vo := '';
    vb := true;   
    DHTMLEdit1.SaveDocument(vo  vb);
  end;
  ...

来源:https://www.tulaoshi.com/n/20160219/1622415.html

延伸阅读
标签: Delphi
  Delphi不仅可调用C++产生的DLL模块,同样C++程序也可调用Delphi所产生的DLL部件。这样交互调用,无须重复开发,大大缩短了生产周期。…… Delphi与VisualBasic、VisualFoxPro等软件一样,属于RAD工具(快速应用开发工具)。适合开发32位或16位/32位混合应用程序。Delphi所使用的程序语言是ObjectPascal,是结构化...
在我的上一篇文章《C#中使用XML读取XML》中和大家讨论了如何使用.NET Framework中提供的类在C#中读取XML以及读取的一些相关概念,那么今天就说一说如何在C#中编写XML文档,起初我觉得用编程的方式去编写XML简直就是自讨苦吃,后来想想还是觉得挺有用的,我想Microsoft那班家伙能编出这些类来应该不是仅仅为了向比尔i盖茨交差吧!至于它的用...
        对于XML,想必各位都比较了解,我也就不用费笔墨来描述它是什么了,我想在未来的Web开发中XML一定会大放异彩,XML是可扩展标记语言,使用它企业可以制定一套自己的数据格式,数据按照这种格式在网络中传输然后再通过XSLT将数据转换成用户期望的样子表示出来,这样便轻易的解决了数据格式不兼容的问...
标签: Delphi
一个成熟的软件,对电子邮件的支持必不可少,用户可以通过点击程序界面上的链接用Delphi实现这一功能,使用非常简单。 首先,在程序的interface部分加入uses Shellapi,因为这个单元封装了我们要使用的API函数。然后,我们就可以写程序了。下面是程序的代码: procedure SendMail var s String begin s = mailtoabc@def...
Delphi的出现将一大批程序员带入了Windows下的可视化编程,为一些C&C++的死党程序员所羡慕、感叹。直到C++Builder的出现这些Programer才用到了梦寐以求的编程工具,也将一些不得已"投敌"到Delphi下的程序员又拉回到C++的怀抱。她正真将Windows下的可视化编程和面向对象编程语言有机的融合在一起。但是由于C++Builder面市时间...

经验教程

617

收藏

52
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部