1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119:
| unit Unit2;
interface
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, comobj, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;
type TForm2 = class(TForm) Memo1: TMemo; Button1: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; IdHTTP1: TIdHTTP; cbXML: TCheckBox; procedure FormCreate(Sender: TObject); procedure FormShow(Sender: TObject); private public end;
var Form2: TForm2; Target : String;
implementation
{$R *.dfm}
procedure MM(s:string); begin Form2.Memo1.Lines.Add(s); end;
procedure ReadXMLFile2(const FileName:TFileName); const Msxml2_DOMDocument='MSXML2.DOMDocument';var XmlDoc, Nodes : OleVariant; sXMLTime, sXMLRate1, sXMLRate2, CURR : String; i : Integer; begin XmlDoc := CreateOleObject(Msxml2_DOMDocument);
sXMLTime:= '*/*/*/@time'; sXMLRate1:= '*/*/*/*/@currency'; sXMLRate2:= '*/*/*/*/@rate';
try XmlDoc.Async := False; XmlDoc.Load(FileName); XmlDoc.SetProperty('SelectionLanguage','XPath'); if (XmlDoc.parseError.errorCode <> 0) then raise Exception.CreateFmt('Error in Xml Data %s',[XmlDoc.parseError]);
try Nodes := XmlDoc.selectNodes(sXMLTime); MM(Nodes.Item(0).Text); Form2.Label1.caption:= Nodes.Item(0).Text; except on E:Exception do MM('0'); end;
CURR:= 'USD';try Nodes := XmlDoc.selectNodes(sXMLRate1); for I := 0 to 1000 do BEGIN if Nodes.Item(I).Text = CURR then BEGIN Form2.Label2.caption:= Nodes.Item(I).Text; Nodes := XmlDoc.selectNodes(sXMLRate2); Form2.Label3.caption:= Nodes.Item(I).Text; Break; END; END; except on E:Exception do MM(CURR+' not exists!'); end;
finally XmlDoc :=Unassigned; end; end;
procedure TForm2.FormCreate(Sender: TObject); var URL : String; fs: TFileStream; begin URL:= 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'; Target:= 'D:\eurofxref-daily.xml'; fs := TFileStream.Create(Target, fmCreate); try IdHTTP1.Get(URL, fs); finally fs.Free; end; end;
procedure TForm2.FormShow(Sender: TObject); var i : Integer; begin MM('Euro foreign exchange reference rates'); MM('The reference rates are usually updated by 3 p.m. C.E.T.'); MM('They are based on a regular daily concertation procedure between'); MM('central banks across Europe and worldwide,'); MM('which normally takes place at 2.15 p.m. CET.'); MM(''); i:=0; repeat Sleep(1000); inc(i); cbXML.Checked:= FileExists(Target); Application.ProcessMessages; until FileExists(Target) or (i>10); if i>10 then ShowMessage('XML-File not exists!'); if FileExists(Target) then begin Memo1.Lines.LoadFromFile(Target); ReadXMLFile2(Target); end; end;
end. |