level 7
正常调用两次才可以让s0有内容,第一次可以打开网页,但是s0是空的。当我把这段代码写到dll文件时,就点击N次也返回空值,请问这个问题怎么解决?
function GetTime() : string; stdcall;
var
iall : IHTMLElement;
s0, s1 : string;
mydt : TDateTime;
Web1 : TWebBrowser;
begin
s0:='';
Web1 := TWebBrowser.Create(nil);
Web1.Navigate('http://open.baidu.com/special/time/');
if Assigned(Web1.Document) then
begin
iall := (Web1.Document AS IHTMLDocument2).body;
while iall.parentElement <> nil do
begin
iall := iall.parentElement;
end;
s0 := iall.outerHTML;
end;
if s0 <> '' then
begin
s1 := s0;
s1 := StrCut(s1 , '日一二三四五六' , '');
s1 := StrCut(s1 , '' , '您的本地电脑时间:');
s1 := StrCut(s1 , 'beijingTimeZone * 60' , '');
s1 := StrCut(s1, 'setTimeout(' , '');
s1 := StrCut(s1, '60000' , '');
s1 := StrCut(s1, 'window' , '');
s1 := StrCut(s1, 'time' , '');
s1 := StrCut(s1, '(' , ');');
s1 := copy(s1 , 1 , 10);
mydt := UnixToDateTime(StrToInt64(s1) + 8 * 60 * 60);
Result := FormatDateTime('yyyy-MM-dd hh:mm:ss' , mydt);
end;
end;
2015年02月17日 04点02分
1
function GetTime() : string; stdcall;
var
iall : IHTMLElement;
s0, s1 : string;
mydt : TDateTime;
Web1 : TWebBrowser;
begin
s0:='';
Web1 := TWebBrowser.Create(nil);
Web1.Navigate('http://open.baidu.com/special/time/');
if Assigned(Web1.Document) then
begin
iall := (Web1.Document AS IHTMLDocument2).body;
while iall.parentElement <> nil do
begin
iall := iall.parentElement;
end;
s0 := iall.outerHTML;
end;
if s0 <> '' then
begin
s1 := s0;
s1 := StrCut(s1 , '日一二三四五六' , '');
s1 := StrCut(s1 , '' , '您的本地电脑时间:');
s1 := StrCut(s1 , 'beijingTimeZone * 60' , '');
s1 := StrCut(s1, 'setTimeout(' , '');
s1 := StrCut(s1, '60000' , '');
s1 := StrCut(s1, 'window' , '');
s1 := StrCut(s1, 'time' , '');
s1 := StrCut(s1, '(' , ');');
s1 := copy(s1 , 1 , 10);
mydt := UnixToDateTime(StrToInt64(s1) + 8 * 60 * 60);
Result := FormatDateTime('yyyy-MM-dd hh:mm:ss' , mydt);
end;
end;