如何编写一个汇率显示软件? 急!在线等。。。。(200)

lb3141

New Member
Member
#1
只要能显示当天,昨天的汇率就ok,软件用delphi编写(单机版),我现在不知道如何获取汇率数据?是不是要访问web服务,如果是,访问接口是什么?
 

Madara

New Member
Member
#9
可以用TCP协议直接连到网站上的80端口,发下URL请求报文的,然后就等网站服务器回数据了。偷懒的话用webbrowser也行,不过那个一用程序得大不少。
 

菜鸟黄

New Member
Member
#11
呵呵~看到你的问题,有点意思就写这东东给你吧unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, MSHTML, OleCtrls, SHDocVw, StrUtils, ExtCtrls;type TForm1 = class(TForm) ListView1: TListView;
Button1: TButton;
Memo1: TMemo;
WebBrowser1: TWebBrowser;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private { Private declarations } procedure MemoToLV(Memo: TMemo;
ListView: TListView);
public { Public declarations } end;
var Form1: TForm1;
LV_s: array [1..8] of string;implementation{$R *.dfm}procedure TForm1.MemoToLV(Memo: TMemo;
ListView: TListView);var s: string;
i,k: integer;
begin
ListView.Items.Clear;
k := 1;
for i:= 0 to Memo.Lines.Count-1do
begin
s := Trim(Memo.Lines.Strings);
if s='<TR>' then
begin
with ListView.Items.Adddo
begin
Caption := LV_s[1];
SubItems.Append(LV_s[2]);
SubItems.Append(LV_s[3]);
SubItems.Append(LV_s[4]);
SubItems.Append(LV_s[5]);
SubItems.Append(LV_s[6]);
SubItems.Append(LV_s[7]);
SubItems.Append(LV_s[8]);
end;
k := 1;
end else
begin
LV_s[k] := s;
inc(k);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.boc.cn/sourcedb/whpj/');
Timer1.Enabled := True;
end;
procedure TForm1.Timer1Timer(Sender: TObject);var k,k1: integer;
s: string;
begin
try Memo1.Clear;
s := IHtmlDocument2(WebBrowser1.Document).Body.outerHTML;
k := pos('<TD class=nav bgColor=#ffffff vAlign=center width=86 align=middle>',s);
k1 := pos('</TR></TBODY></TABLE></TD></TR></TBODY></TABLE>',s);
s := copy(s,k,k1-k);
s := AnsiReplaceText(s, '<TD class=nav bgColor=#ffffff vAlign=center width=86 align=middle>', '');
s := AnsiReplaceText(s, '</TD>', '');
s := AnsiReplaceText(s, '</TR>', '')+#13#10+'<TR>';
Memo1.Lines.Append(s);
MemoToLV(Memo1,ListView1);
Timer1.Enabled := False;
except end;
end;
end.
 

Users Who Are Viewing This Thread (Users: 1, Guests: 0)