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;