Delphi程序开发1
2020-02-18 07:25
519 查看
第一次写博客,记录一下自己的学习过程。
用Delphi读取XML文件,获取xml文件的节点值,并输出。
代码 unit Track; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,XMLDoc,XMLIntf,StdCtrls,msXML,XMLDom, Vcl.Grids, AdvObj, BaseGrid, AdvGrid, Vcl.ExtCtrls, Classes, Controls, ExtCtrls, Grids; type sTrack =class(TObject) WaferId:string; Snum,Gnum:integer; end; TForm1 = class(TForm) panel: TPanel; procedure FormCreat(Sender:TObject); private { Private declarations } function RoundFloat(f: double; i: Integer): double; public { Public declarations } Tracklist: Tstringlist; procedure GetXmlData(); end; var Form1: TForm1; implementation {$R *.dfm} function TForm1.RoundFloat(f: double; i: Integer): double; var s: string; ef: Extended; begin if f = 0 then begin Result := 0; Exit; end; s := '#.' + StringOfChar('0', i); if s = '#.' then s := '#'; ef := StrToFloat(FloatToStr(f)); // 防止浮点运算的误差 Result := StrToFloat(FormatFloat(s, ef)); end; procedure TForm1.FormCreat(Sender: TObject); begin screen.Cursor:=crHourGlass; GetXmlData; screen.Cursor:=crDefault; end; procedure TForm1.GetXmlData; //从xml中查找数据 var XmlDoc:TXMLDocument; rootnode,snode,t1node,t2node,wnode,s,t: IXMLnode; nodelist,slist:IXMLNodelist; i,n:integer; count,icount:integer; cTrack:sTrack; begin Tracklist:=TStringList.Create; XmlDoc:=TXMLDocument.Create(nil); XmlDoc.FileName:='C:\Users\Administrator\Desktop\Inspection_JOB_CJ2_PJ2_20171207_034414.xml';//访问的xml文件的路径 XmlDoc.Active:=true; rootnode:=XmlDoc.DocumentElement; //表示xmlDoc的根节点 nodelist:=rootnode.ChildNodes; //根节点下的子节点 count:=nodelist.Count; //根节点下的子节点个数 if rootnode <>nil then //遍历需要的子节点 begin t:=nodelist[11].ChildNodes[1].ChildNodes[1].ChildNodes[1]; //LotIdHash/Values/I/Values slist:=t.ChildNodes; icount:=slist.Count; //LotIdHash/Values/I/Values下的子节点个数,子节点(T,I) for i := 1 to icount-1 do begin cTrack:=sTrack.Create; s:=t.ChildNodes[i]; //I节点 t1node:=s.ChildNodes[0].ChildNodes[0].ChildNodes[1]; //I/Trackers/I/NumInspectedDie节点 t2node:=s.ChildNodes[0].ChildNodes[0].ChildNodes[11]; //I/Trackers/I/NumGoodDie节点 wnode:=s.ChildNodes[1].childNodes[1]; //I/SubstrateDetails/WaferId cTrack.WaferId:=wnode.NodeValue; cTrack.Snum:=t1node.NodeValue; cTrack.Gnum:=t2node.NodeValue; TrackList.AddObject(cTrack.WaferId,cTrack); end;//存放到Tstringlist中 with Grid1 do//输出到grid1 begin RowCount:=TrackList.Count+1; for n := 0 to TrackList.Count-1 do begin cTrack:=sTrack(TrackList.Objects ); Delete(cTrack.WaferId,7,3); Cells[0,n+1]:=cTrack.WaferId; Objects[0,n+1]:=cTrack; Cells[1,n+1]:= FloatToStr(RoundFloat(cTrack.Gnum/cTrack.Snum,4)*100); end; end; end; end; end.
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- delphi调用SQL serever存储过程的问题
- 利用Delphi 5中调用Excel 97
- Delphi 64与32位的差异
- Using WinInet functions to download a file asynchronously in Delphi
- Delphi中API编程-编译实现
- Delphi Win32核心API参考-窗口创建
- How to Set Currency Field DisplayFormat without Currency Symbol in Delphi
- Delphi Tmessage标准消息详解
- delphi 获取MAC地址
- delphi 获取文件的相关时间
- Delphi 中串口通讯的实现
- Delphi中MsComm控件的安装使用
- Delphi读取本机存在的串口
- delphi6+winxp的DLL断点调试
- DELPHI 控制EXCEL
- Delphi 2007 安装程序不能放在中文目录下安装.
- DELPHI国外经典站
- delphi中PE文件结构
- delphi中使用ADOQuery时的中文参数问题
- 通过delphi将秒数转换成日期格式