操作系统  办公  实用知识  设计  开发  WEB开发  移动开发  数据库  软件工程  网管  安全  管理  信息化  答疑  渠道 

delphi学习:两种方法使用xml文档

2006-4-24 作者:oklemon 转载自:CSDN 网友评论 0 条 点击进入论坛

 使用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; 
  ...
  //本文为转贴,作者不详,仅供大家参考

已有 0 位对此文章感兴趣的网友发布了看法    
我来评两句 登录邮箱: 密码:
  匿名发表
今日推荐
技术文库(共有 46430 篇文章)
操作系统
办公软件
实用知识
网络管理
软件开发
WEB开发
软件工程
数据库
设计在线
信息安全
行业信息化
管理信息化
重点推荐
电子杂志订阅
点击电子杂志名称查看样刊
输入E-mail地址即可订阅
E-mail