procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
sleep(Random(10));
tip:=Random(strnum);
sLabel1.Font.Color:=rgb(34,122,203); //字体颜色
sLabel1.Caption:=str[tip]+' 查看详情>>';
GetLocalTime(SysTime); //本地时间
//GetSystemTime(SysTime); //乔治格林时间
temp:=GetWebPage('http://www.ip138.com/ips1388.asp');
Delete(temp,1,Pos(' 来自',temp)+6); //Pos()函数对汉字怎么进行使用?
temp:=Copy(temp,1,Pos('<',temp)-1);
lastini:=Tinifile.Create('.\lastrun.ini');
if lastini.readinteger('上次运行','lastrun',0)=0 then
begin
sLabel2.Caption:=IntToStr(SysTime.wYear)+'-'+IntToStr(SysTime.wMonth)+'-'+IntToStr(SysTime.wDay)+' '+IntToStr(SysTime.wHour)+':'+IntToStr(SysTime.wMinute);
sLabel3.Caption:=temp;
end
else
begin
a0:=lastini.readinteger('年','year',1); //读取ini文件
a1:=lastini.readinteger('月','month',1);
a2:=lastini.readinteger('日','day',1);
a3:=lastini.readinteger('时','hour',1);
a4:=lastini.readinteger('分','minute',1);
sLabel2.Caption:=IntToStr(a0)+'-'+IntToStr(a1)+'-'+IntToStr(a2)+' '+IntToStr(a3)+':'+IntToStr(a4);
sLabel3.Caption:=lastini.readstring('地点','locale',''); //显示上次信息
end;
end;
procedure TForm1.FormDestroy(Sender: TObject); //信息写入ini文件
var
lastini: Tinifile;
begin
lastini:=Tinifile.Create('.\lastrun.ini');
if sLabel2.Caption='' then lastini.writeinteger('上次运行','lastrun',0)
else
begin
lastini.writeinteger('上次运行','lastrun',1);
lastini.writeinteger('年','year',SysTime.wYear);
lastini.writeinteger('月','month',SysTime.wMonth);
lastini.writeinteger('日','day',SysTime.wDay);
lastini.writeinteger('时','hour',SysTime.wHour);
lastini.writeinteger('分','minute',SysTime.wMinute);
lastini.writestring('地点','locale',temp);
end;
end;
function TForm1.GetWebPage(const Url: string; IsUtf8: Boolean): string; //通过外网获取ip,地理信息,Ps:这段子程序来自网友的。
var
idp:TidHTTP;
begin
Result:='';
idp:=TIdHTTP.Create(Application);
try
idp.HandleRedirects:=True;
idp.Request.UserAgent:='Mozilla/5.0';
Result:=idp.Get(Url);
if IsUtf8 then
Result:=Utf8ToAnsi(Result);
finally
FreeAndNil(idp);
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject); //查看按钮事件
begin
ShellExecute(handle,nil,pchar('http://www.baidu.com/s?wd='+str[tip]+'&rsv_bp=0&rsv_spt=3&rsv_sug3=3&rsv_sug1=3&rsv_sug4=203&inputT=1021'),nil,nil,sw_shownormal);
//打开搜索内容
Form1.Close;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ANimateWindow(handle,400,aw_slide+aw_ver_positive+aw_hide); //窗口关闭效果:自顶向下,400us
end;