请问下面的源程序为什么运行不过去,老是出现错误? (100分)

  • 主题发起人 主题发起人 pfpf0365
  • 开始时间 开始时间
P

pfpf0365

Unregistered / Unconfirmed
GUEST, unregistred user!
请问下面的源程序为什么运行不过去,老是出现错误? 谢谢大家?
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Psock, NMHttp, StdCtrls, Buttons, ComCtrls, ExtCtrls;

type
TForm1 = class(TForm)
NMHTTP1: TNMHTTP;
GroupBox1: TGroupBox;
Memo1: TMemo;
SaveDialog1: TSaveDialog;
StatusBar1: TStatusBar;
Panel1: TPanel;
Panel2: TPanel;
GroupBox2: TGroupBox;
RadioChina: TRadioButton;
RadioInter: TRadioButton;
GroupBox3: TGroupBox;
RadioNight: TRadioButton;
RadioMorning: TRadioButton;
Panel3: TPanel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
procedure Button1Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
Content,Content1,contentTitle,MixTemperture,MaxTemperture,TempTemperture:string;
StrOldCity,strnewCity: array[1..33] of string;
StrCity,StrTemp:string;
i,j:integer;
begin
Screen.Cursor:=crHourGlass;
StatusBar1.Panels[0].Text:='正在下载天气信息,请等候........';
memo1.text:='';
if RadioChina.checked then
begin
StrOldCity[1]:='上海市';
StrOldCity[2]:='天津市';
StrOldCity[3]:='重庆市';
StrOldCity[4]:='长春市';
StrOldCity[5]:='沈阳市';
StrOldCity[6]:='哈尔滨市';
StrOldCity[7]:='石家庄市';
StrOldCity[8]:='太原市';
StrOldCity[9]:='济南市';
StrOldCity[10]:='合肥市';
StrOldCity[11]:='南京市';
StrOldCity[12]:='杭州市';
StrOldCity[13]:='南昌市';
StrOldCity[14]:='福州市';
StrOldCity[15]:='郑州市';
StrOldCity[16]:='武汉市';
StrOldCity[17]:='长沙市';
StrOldCity[18]:='广州市';
StrOldCity[19]:='海口市';
StrOldCity[20]:='香港';
StrOldCity[21]:='西安市';
StrOldCity[22]:='兰州市';
StrOldCity[23]:='西宁市';
StrOldCity[24]:='银川市';
StrOldCity[25]:='乌鲁木齐市';
StrOldCity[26]:='昆明市';
StrOldCity[27]:='拉萨市';
StrOldCity[28]:='成都市';
StrOldCity[29]:='南宁市';
StrOldCity[30]:='贵阳市';
StrOldCity[31]:='呼和浩特市';
StrOldCity[32]:='台北市';
StrOldCity[33]:='澳门';
end;
if RadioInter.Checked then
begin
StrOldCity[1]:='东京';
StrOldCity[2]:='曼谷';
StrOldCity[3]:='卡拉奇';
StrOldCity[4]:='法兰克福';
StrOldCity[5]:='莫斯科';
StrOldCity[6]:='开罗';
StrOldCity[7]:='巴黎';
StrOldCity[8]:='伦敦';
StrOldCity[9]:='悉尼';
StrOldCity[10]:='纽约';
end;
try
if ((RadioChina.Checked ) and (RadioMorning.checked)) then
//国内早间天气预报
begin
Content1:='';
NMHTTP1.get('http://www.grmc.gov.cn/fct/inland.htm');
Content:=Nmhttp1.Body;
Content:=Copy(content,Pos('气温',content),length(Content));
ContentTitle:=FormatDateTime('mm"月"dd"日早8时"',now+1);
ContentTitle:=ContentTitle+FormatDateTime('"至"mm"月"dd"日早8时"',now+2);
Content:=Copy(Content,Pos('</TR>',Content)+5,length(Content));
Content:=Copy(Content,Pos('<TR>',Content)+4,length(Content));
while Pos('<TD>',content)>0 do
begin
Content1:='';
Content:=Copy(Content,Pos('<TD>',Content)+5,length(Content));
content1:=Content1+trim(Copy(Content,Pos('>',Content)+1,Pos('</',content)-Pos('>',Content)-1));
Strcity:=trim(Content1);
Content1:='天气预报'+#13#10+ContentTitle+',';
///天气状况
Content:=Copy(Content,Pos('<TD>',Content)+1,length(Content));
content1:=Content1+trim(Copy(Content,Pos('>',Content)+1,Pos('</',content)-Pos('>',Content)-1))+',';

Content:=Copy(Content,Pos('<TD>',Content)+1,length(Content));
TempTemperture:=Copy(Content,Pos('>',Content)+1,Pos('</',Content)-Pos('>',Content)-1);

MixTemperture:='';
MaxTemperture:='';
if Pos('--',TempTemperture)>0 then
begin

//MixTemperture:='最低气温'+trim(Copy(TempTemperture,1,Pos('--',TempTemperture)-1))+',';
MaxTemperture:='最高气温'+trim(Copy(TempTemperture,Pos('--',TempTemperture)+2,length(TempTemperture)))+',';
end else MaxTemperture:=trim(Copy(Content,Pos('>',Content)+1,Pos('</',content)-Pos('>',Content)-1))+',';
Content:=Copy(Content,Pos('<TD>',Content)+1,length(Content));
Content:=Copy(Content,Pos('<TD>',Content)+1,length(Content));

TempTemperture:=Copy(Content,Pos('>',Content)+1,Pos('</',Content)-Pos('>',Content)-1);
if Pos('--',TempTemperture)>0 then
begin

MixTemperture:='最低气温'+trim(Copy(TempTemperture,1,Pos('--',TempTemperture)-1))+',';
//MaxTemperture:='最高气温'+trim(Copy(TempTemperture,Pos('--',TempTemperture)+2,length(TempTemperture)))+',';
end else MixTemperture:=trim(Copy(Content,Pos('>',Content)+1,Pos('</',content)-Pos('>',Content)-1))+',';
content1:=Content1+MaxTemperture+MixTemperture ;

Content1:=Content1+'风力1-2级'+#13#10+#13#10+#13#10;
For i:=1 to 33 do
if Pos(StrCity,strOldCity)>0 then StrNewCity:=strOldCity+Content1;
end;

end;

if ((RadioChina.Checked ) and (RadioNight.checked)) then
//国内晚间天气预报
begin
Content1:='';
NMHTTP1.get('http://www.grmc.gov.cn/fct/inland.htm');
Content:=Nmhttp1.Body;
Content:=Copy(content,Pos('气温',content),length(Content));
ContentTitle:=FormatDateTime('mm"月"dd"日20时至"',now);
ContentTitle:=ContentTitle+FormatDateTime('mm"月"dd"日20时"',now+1);
Content:=Copy(Content,Pos('</TR>',Content)+5,length(Content));
Content:=Copy(Content,Pos('<TR>',Content)+4,length(Content));

while Pos('<TD>',content)>0 do
begin
Content1:='';
Content:=Copy(Content,Pos('<TD>',Content)+5,length(Content));
content1:=Content1+trim(Copy(Content,Pos('>',Content)+1,Pos('</',content)-Pos('>',Content)-1));
Strcity:=trim(Content1);
Content1:='市天气预报'+#13#10+ContentTitle+',';
///天气状况
Content:=Copy(Content,Pos('<TD>',Content)+1,length(Content));
content1:=Content1+trim(Copy(Content,Pos('>',Content)+1,Pos('</',content)-Pos('>',Content)-1))+',';

Content:=Copy(Content,Pos('<TD>',Content)+1,length(Content));
TempTemperture:=Copy(Content,Pos('>',Content)+1,Pos('</',Content)-Pos('>',Content)-1);

MixTemperture:='';
MaxTemperture:='';
if Pos('--',TempTemperture)>0 then
begin

MixTemperture:='最低气温'+trim(Copy(TempTemperture,1,Pos('--',TempTemperture)-1))+',';
MaxTemperture:='最高气温'+trim(Copy(TempTemperture,Pos('--',TempTemperture)+2,length(TempTemperture)))+',';
//content1:=Content1+MixTemperture+'最高气温'+trim(Copy(TempTemperture,Pos('--',TempTemperture)+2,length(TempTemperture)))+',';
end else TempTemperture:=trim(Copy(Content,Pos('>',Content)+1,Pos('</',content)-Pos('>',Content)-1))+',';
if not RadioNight.Checked then
content1:=Content1+MaxTemperture+MixTemperture
else
content1:=Content1+MixTemperture+MaxTemperture;

Content1:=Content1+'风力1-2级'+#13#10+#13#10+#13#10;
For i:=1 to 33 do
if Pos(StrCity,strOldCity)>0 then StrNewCity:=strOldCity+Content1;
Content:=Copy(Content,Pos('<TD>',Content)+1,length(Content));
Content:=Copy(Content,Pos('<TD>',Content)+1,length(Content));
end;
end;

if RadioInter.Checked then
//国际早间天气预报
begin
Content1:='';
NMHTTP1.get('http://www.grmc.gov.cn/fct/inter.htm');
Content:=Nmhttp1.Body;
Content:=Copy(content,Pos('气温',content),length(Content));
if Radionight.checked then ContentTitle:=FormatDateTime('mm"月"dd"日"',now)
else ContentTitle:=FormatDateTime('mm"月"dd"日"',now+1);
Content:=Copy(Content,Pos('<tr>',Content)+5,length(Content));

while Pos('<TD>',content)>0 do
begin
Content1:='';
Content:=Copy(Content,Pos('<TD>',Content)+5,length(Content));
content1:=Content1+trim(Copy(Content,Pos('>',Content)+1,Pos('</',content)-Pos('>',Content)-1));
Strcity:=trim(Content1);
Content1:=Content1+'天气预报'+#13#10+ContentTitle+',';
///天气状况
Content:=Copy(Content,Pos('<TD>',Content)+1,length(Content));
content1:=Content1+trim(Copy(Content,Pos('>',Content)+1,Pos('</',content)-Pos('>',Content)-1))+',';

Content:=Copy(Content,Pos('<TD>',Content)+1,length(Content));
TempTemperture:=Copy(Content,Pos('>',Content)+1,Pos('</',Content)-Pos('>',Content)-1);

MixTemperture:='';
MaxTemperture:='';
if Pos('--',TempTemperture)>0 then
begin

MixTemperture:='最低气温'+trim(Copy(TempTemperture,1,Pos('--',TempTemperture)-1))+',';
MaxTemperture:='最高气温'+trim(Copy(TempTemperture,Pos('--',TempTemperture)+2,length(TempTemperture)))+',';
//content1:=Content1+MixTemperture+'最高气温'+trim(Copy(TempTemperture,Pos('--',TempTemperture)+2,length(TempTemperture)))+',';
end else TempTemperture:=trim(Copy(Content,Pos('>',Content)+1,Pos('</',content)-Pos('>',Content)-1))+',';
if not RadioNight.Checked then
content1:=Content1+MaxTemperture+MixTemperture
else
content1:=Content1+MixTemperture+MaxTemperture;

Content1:=Content1+'风力1-2级'+#13#10+#13#10+#13#10;
For i:=1 to 10 do
if Pos(strOldCity,StrCity)>0 then StrNewCity:=Content1;
end;
end;

except
showmessage('不能连接网站,请检查网络是上网!');
StatusBar1.Panels[0].Text:='';
Screen.Cursor:=crDefault;
end;
Content1:='';
Content:='';
j:=0;
For i:=1 to 33 do
begin
if StrNewCity<>'' then
j:=j+1
else Content:=Content+StroldCity+',';
Content1:=Content1+StrNewCity;
end;
memo1.text:=#13#10+trim(Content1);
Content:=Copy(Content,1,length(Content)-1);
StatusBar1.Panels[0].Text:='下载完毕!';
StatusBar1.Panels[1].Text:='共下载城市天气情况:'+inttostr(j);
if Content<>',,,,,,,,,,,,,,,,,,,,,,' then StatusBar1.Panels[2].Text:='缺少下载城市为:'+Content;
Screen.Cursor:=crDefault;
end;

procedure TForm1.BitBtn3Click(Sender: TObject);
begin
close;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
var
f:textfile;
i:integer;
begin
if SaveDialog1.Execute then
begin
if FileExists(SaveDialog1.FileName) then
if Application.MessageBox('已有此文件,你要替换吗?','提示',
MB_OKCANCEL + MB_DEFBUTTON1) = IDOK then deletefile(SaveDialog1.FileName);
AssignFile(f,SaveDialog1.FileName);
Rewrite(f);
Writeln(f,'');
for i:=0 to Memo1.lines.count-1 do
Writeln(f,trim(Memo1.lines));
CloseFile(f);
end;

end;

end.
我刚学习delphi。请告诉我为什么?
 
错误提示什么??
还是运行结果不对??
 
晕,
运行到哪里不对.
 
给你一段我以前写的从网上下载天气信息的代码
先是用nmhttp下载一个页面,将html代码输入一个memo框,之后从memo中分拣

下面是分拣需要信息的代码:

var
m,n,PosReturn,SkipChars,CityNo,i,PosStr : Integer;
strLineBuf,cityBuf:string;
CityInfo:array[1..5] of string; //各个城市的所有天气信息
tdNo,ilast,aDot,bDot,k:integer;
ss:TStringList;
tmpStr,strtd,tmptd,city:string;
begin
//获取城市所有信息
cityBuf:=edit10.Text;
SkipChars := 0;
for m := 0 to memo2.lines.Count do
begin
posReturn := Pos (cityBuf,Memo2.Lines[m]);
if PosReturn<> 0 then
begin
SkipChars := 0;
for n:=0 to m-1 do
begin
Skipchars := SkipChars + Length(Memo2.Lines[n]);
end;
skipChars := SkipChars + PosReturn-1;
break;
end;
end;
tmpStr := copy(Memo2.Text,skipchars,length(memo2.text)-skipchars);
memo3.Text:=tmpStr;
skipchars:=0;
for i := 1 to 5 do
begin
posStr := pos('</td>',tmpstr);
if posstr<>0 then
begin
tmptd :=copy(tmpstr,1,posStr+4);
strtd := strtd+tmptd;
tmpstr:=rightStr(tmpstr,(length(tmpstr)-length(tmptd)));
end;
end;

//过滤信息
SearchAndReplace(strtd,' ','');
SearchAndReplace(strtd,' ','');
memo3.Text:=strtd;
// skipinfo:=0;
for k:= 1 to 5 do
begin
aDot:=pos('>',strtd);
if aDot<>0 then
begin
bDot :=pos('</td>',strtd);
if bDot<>0 then
begin
cityinfo[k] := copy(strtd,aDot+1,bDot-aDot-1);
strtd:=rightStr(strtd,length(strtd)-bDot-4);
end;
end;
end;
edit5.Text:=cityinfo[1]; //城市名
edit7.Text:=cityinfo[2]; //天气状况
edit9.Text:=cityinfo[3]; //风向
edit6.Text:=cityinfo[4]; //最高气温
edit8.Text:=cityinfo[5]; //最低气温
end;

http取自tom网,如果把edit控件转为数据库插入代码,加循环,就能一次把所有网页上所有有关天气下载了
 
NMHTTP1控件指向的http://www.grmc.gov.cn/fct/inland.htm
这一网页是无效的,所以不能获得信息了
 
新的气象信息已经换地方了:
http://www.nmc.gov.cn/cgi-bin/cgi200010/query?04
这里有三个框架
内容在
http://www.nmc.gov.cn/tongxt/fsct.html

你的程序不能适合新的格式了
所以你得重新写。
 
就是呀,把错误的地方贴出来吗?不然谁会去帮你找
 
谢谢大家这么有耐心看完并指出错误,我是初学,想试试,没想到。在这里再次谢谢大家[:D]
 
后退
顶部