开发者

Set timer on procedure?

i'm building an application with a Twebbrowser component that needs to navigate to only 1 Page, the application will be in the Windows autostart so it's possible that there isn't any internet connectivity on the first navigate, so i want to check for the title of the page, if it's not the right one, navigate again. Like this:

procedure TForm1.titlechange(Sender:开发者_开发问答 TObject; const Text: WideString);
begin
if Text = 'Untitled Document' then
begin
StaticText1.Visible := False;
Timer4.Enabled := False;
end
else
webbrowser1.Navigate('http://website.com');
end;

I want to have a 5 second timer on that procedure, and if the navigation was successful and the title is "Untitled Document" the timer should be disabled.

How can i do that ?

Thanks!


i am back to my original request, i implemented the proposed solution, this does only work sometimes, if there's no network connected sometimes there's a "Navigation to the Webpage was canceled" this triggers OnDocumentComplete i am thinking that the LocationName function in Twebbrowser itself has a wrong functionality description.

My original code however does work, i just need a timer on it ! Can someone help me with that please.


Try using the OnNavigatError and OnDocumentComplete events instead, eg:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer4Timer(nil);
end; 

procedure TForm1.Timer4Timer(Sender: TObject);
begin
  Timer4.Enabled := False;
  webbrowser1.Navigate('http://website.com');
end;

procedure TForm1.webbrowser1NavigateError(ASender: TObject; const pDisp: IDispatch; var URL: OleVariant; var Frame: OleVariant; var StatusCode: OleVariant; var Cancel: WordBool);
begin
  Timer4.Enabled := True;
end;

procedure TForm1.webbrowser1DocumentComplete(ASender: TObject; const pDisp: IDispatch; var URL: OleVariant);
begin
  if webbrowser1.LocationName = 'Untitled Document' then
  begin
    StaticText1.Visible := False;
  end
  else begin
    Timer4.Enabled := True;
  end;
end; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜