<?xml version="1.0" encoding="utf-8"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>DaniWeb IT Discussion Community</title>
		<link>http://www.daniweb.com/forums/</link>
		<description>Tech support, programming, web development, and internet marketing community. Forums to get free computer help and support.</description>
		<language>en-US</language>
		<lastBuildDate>Tue, 01 Dec 2009 04:24:36 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.daniweb.com/alphaimages/misc/rss.jpg</url>
			<title>DaniWeb IT Discussion Community</title>
			<link>http://www.daniweb.com/forums/</link>
		</image>
		<item>
			<title>Wait for page to load</title>
			<link>http://www.daniweb.com/forums/thread231990.html</link>
			<pubDate>Wed, 21 Oct 2009 14:32:06 GMT</pubDate>
			<description>Greetings fellow coders, I have read many tutorials, and tried many different code snippets but I have hit a brick wall and decided its time to give my brain a rest and see if other coders can find a solution. 
with the push of a button I will log into a web site, do some tasks, then log out. 
 
I...</description>
			<content:encoded><![CDATA[<div>Greetings fellow coders, I have read many tutorials, and tried many different code snippets but I have hit a brick wall and decided its time to give my brain a rest and see if other coders can find a solution.<br />
with the push of a button I will log into a web site, do some tasks, then log out.<br />
<br />
I got the log in no problem, however my wall is going to the next link...<br />
<br />
The page is NOT waiting to load before continuing.<br />
<br />
As the code is NOW it logs in and before logging i even completes it goes to the next link so log in actually fails.<br />
<br />
 <pre style="margin:20px; line-height:13px">unit Unit1;<br />
<br />
interface<br />
<br />
uses<br />
&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br />
&nbsp; Dialogs, ToolWin, ComCtrls, Menus, ActnMan, ActnCtrls, ActnMenus,<br />
&nbsp; TabNotBk, jpeg, ExtCtrls, OleCtrls, SHDocVw, StdCtrls, PNGButton, mshtml,<br />
&nbsp; Buttons, inifiles;<br />
<br />
type<br />
&nbsp; TForm1 = class(TForm)<br />
&nbsp; &nbsp; MainMenu1: TMainMenu;<br />
&nbsp; &nbsp; Options1: TMenuItem;<br />
&nbsp; &nbsp; opt_switch: TMenuItem;<br />
&nbsp; &nbsp; opt_exit: TMenuItem;<br />
&nbsp; &nbsp; Help1: TMenuItem;<br />
&nbsp; &nbsp; hlp_about<b></b>: TMenuItem;<br />
&nbsp; &nbsp; Panel1: TPanel;<br />
&nbsp; &nbsp; Image2: TImage;<br />
&nbsp; &nbsp; Panel2: TPanel;<br />
&nbsp; &nbsp; PageControl1: TPageControl;<br />
&nbsp; &nbsp; TabSheet1: TTabSheet;<br />
&nbsp; &nbsp; Panel3: TPanel;<br />
&nbsp; &nbsp; WebBrowser1: TWebBrowser;<br />
&nbsp; &nbsp; CoolBar1: TCoolBar;<br />
&nbsp; &nbsp; Animate1: TAnimate;<br />
&nbsp; &nbsp; ToolBar1: TToolBar;<br />
&nbsp; &nbsp; png_btn_home: TPNGButton;<br />
&nbsp; &nbsp; png_btn_back: TPNGButton;<br />
&nbsp; &nbsp; png_btn_forward: TPNGButton;<br />
&nbsp; &nbsp; png_btn_stop: TPNGButton;<br />
&nbsp; &nbsp; png_btn_refresh: TPNGButton;<br />
&nbsp; &nbsp; URLs: TEdit;<br />
&nbsp; &nbsp; StaticText1: TStaticText;<br />
&nbsp; &nbsp; StaticText2: TStaticText;<br />
&nbsp; &nbsp; StaticText3: TStaticText;<br />
&nbsp; &nbsp; StaticText4: TStaticText;<br />
&nbsp; &nbsp; StaticText5: TStaticText;<br />
&nbsp; &nbsp; Button1: TButton;<br />
&nbsp; &nbsp; cur_user: TEdit;<br />
&nbsp; &nbsp; Button2: TButton;<br />
&nbsp; &nbsp; TabSheet2: TTabSheet;<br />
&nbsp; &nbsp; updates: TMemo;<br />
&nbsp; &nbsp; Button3: TButton;<br />
&nbsp; &nbsp; StaticText6: TStaticText;<br />
&nbsp; &nbsp; procedure png_btn_homeClick(Sender: TObject);<br />
&nbsp; &nbsp; procedure png_btn_backClick(Sender: TObject);<br />
&nbsp; &nbsp; procedure png_btn_forwardClick(Sender: TObject);<br />
&nbsp; &nbsp; procedure png_btn_stopClick(Sender: TObject);<br />
&nbsp; &nbsp; procedure png_btn_refreshClick(Sender: TObject);<br />
&nbsp; &nbsp; procedure WebBrowser1CommandStateChange(Sender: TObject;<br />
&nbsp; &nbsp; &nbsp; Command: Integer; Enable: WordBool);<br />
&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br />
&nbsp; &nbsp; procedure FindAddress;<br />
&nbsp; &nbsp; procedure WebBrowser1BeforeNavigate2(Sender: TObject;<br />
&nbsp; &nbsp; &nbsp; const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,<br />
&nbsp; &nbsp; &nbsp; Headers: OleVariant; var Cancel: WordBool);<br />
&nbsp; &nbsp; procedure opt_exitClick(Sender: TObject);<br />
&nbsp; &nbsp; procedure WebBrowser1DownloadBegin(Sender: TObject);<br />
&nbsp; &nbsp; procedure WebBrowser1DownloadComplete(Sender: TObject);<br />
&nbsp; &nbsp; procedure URLsKeyPress(Sender: TObject; var Key: Char);<br />
&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br />
&nbsp; &nbsp; procedure WebBrowser1NavigateComplete2(Sender: TObject;<br />
&nbsp; &nbsp; &nbsp; const pDisp: IDispatch; var URL: OleVariant);<br />
&nbsp; &nbsp; procedure WebBrowser1DocumentComplete(Sender: TObject;<br />
&nbsp; &nbsp; &nbsp; const pDisp: IDispatch; var URL: OleVariant);<br />
<br />
<br />
&nbsp; private<br />
&nbsp; &nbsp; { Private declarations }<br />
&nbsp; public<br />
&nbsp; &nbsp; { Public declarations }<br />
&nbsp; end;<br />
<br />
var<br />
&nbsp; Form1: TForm1;<br />
&nbsp; CurDispatch: IDispatch; {save the interface globally }<br />
<br />
implementation<br />
<br />
{$R *.dfm}<br />
<br />
<br />
<br />
procedure TForm1.FormCreate(Sender: TObject);<br />
begin<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { Load the animation from the AVI file in the startup directory.}<br />
&nbsp; &nbsp; Animate1.FileName := ExtractFilePath(Application.ExeName) + 'cool.avi';<br />
&nbsp; &nbsp; WebBrowser1.Navigate('http://MYSITE.com/');<br />
&nbsp; end;<br />
<br />
procedure TForm1.FindAddress;<br />
var<br />
&nbsp; Flags: OLEVariant;<br />
<br />
begin<br />
&nbsp; Flags := 0;<br />
&nbsp; WebBrowser1.Navigate(WideString(Urls.Text), Flags, Flags, Flags, Flags);<br />
end;<br />
<br />
procedure TForm1.png_btn_homeClick(Sender: TObject);<br />
&nbsp; begin<br />
&nbsp; &nbsp; WebBrowser1.Navigate('MYSITE.com');<br />
&nbsp; end;<br />
<br />
procedure TForm1.png_btn_backClick(Sender: TObject);<br />
&nbsp; begin<br />
&nbsp; &nbsp; WebBrowser1.GoBack; //This will GoBack in the browser<br />
&nbsp; end;<br />
<br />
procedure TForm1.png_btn_forwardClick(Sender: TObject);<br />
&nbsp; begin<br />
&nbsp; &nbsp; WebBrowser1.GoForward; //This will go Forward<br />
&nbsp; end;<br />
<br />
procedure TForm1.png_btn_stopClick(Sender: TObject);<br />
&nbsp; begin<br />
&nbsp; &nbsp; WebBrowser1.Stop; //This will stop the browser<br />
&nbsp; &nbsp; Animate1.Active := False; // Stop the avi and show the first frame<br />
&nbsp; end;<br />
<br />
procedure TForm1.png_btn_refreshClick(Sender: TObject);<br />
&nbsp; var<br />
&nbsp; &nbsp; vRefresh : OleVariant;<br />
&nbsp; begin<br />
&nbsp; &nbsp; vRefresh := 3;<br />
&nbsp; &nbsp; WebBrowser1.Refresh2(OLEVariant(vRefresh));<br />
&nbsp; end;<br />
<br />
procedure TForm1.WebBrowser1CommandStateChange(Sender: TObject;<br />
&nbsp; Command: Integer; Enable: WordBool);<br />
&nbsp; begin<br />
&nbsp; &nbsp; case Command of<br />
&nbsp; &nbsp; &nbsp; CSC_NAVIGATEBACK: png_btn_back.Enabled := Enable;<br />
&nbsp; &nbsp; &nbsp; CSC_NAVIGATEFORWARD: png_btn_forward.Enabled := Enable;<br />
&nbsp; &nbsp; end;<br />
&nbsp; end;<br />
<br />
procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject;<br />
&nbsp; const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,<br />
&nbsp; Headers: OleVariant; var Cancel: WordBool);<br />
&nbsp; &nbsp; begin<br />
&nbsp; &nbsp; &nbsp; URLs.Text := URL;<br />
&nbsp; &nbsp; end;<br />
<br />
procedure TForm1.WebBrowser1DownloadBegin(Sender: TObject);<br />
&nbsp; begin<br />
&nbsp; &nbsp; Animate1.Active := True; //Play the avi from the first frame indefinitely<br />
&nbsp; end;<br />
<br />
procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);<br />
&nbsp; begin<br />
&nbsp; &nbsp; Animate1.Active := False; // Stop the avi and show the first frame<br />
&nbsp; end;<br />
<br />
procedure TForm1.WebBrowser1NavigateComplete2(Sender: TObject;<br />
&nbsp; const pDisp: IDispatch; var URL: OleVariant);<br />
&nbsp; begin<br />
&nbsp; &nbsp; if CurDispatch = nil then<br />
&nbsp; &nbsp; &nbsp; CurDispatch := pDisp; { save for comparison }<br />
&nbsp; end;<br />
<br />
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;<br />
&nbsp; const pDisp: IDispatch; var URL: OleVariant);<br />
&nbsp; begin<br />
&nbsp; &nbsp; if (pDisp = CurDispatch) then<br />
&nbsp; &nbsp; &nbsp; begin<br />
&nbsp; &nbsp; &nbsp; &nbsp; CurDispatch := nil; {clear the global variable }<br />
&nbsp; &nbsp; &nbsp; end;<br />
&nbsp; end;<br />
<br />
procedure TForm1.URLsKeyPress(Sender: TObject; var Key: Char);<br />
&nbsp; begin<br />
&nbsp; &nbsp; if (Key=#13) then<br />
&nbsp; &nbsp; &nbsp; begin<br />
&nbsp; &nbsp; &nbsp; &nbsp; WebBrowser1.Navigate(URLs.Text);<br />
&nbsp; &nbsp; &nbsp; end;<br />
&nbsp; end;<br />
<br />
<br />
procedure TForm1.Button1Click(Sender: TObject);<br />
&nbsp; var iDoc: IHtmlDocument2;<br />
&nbsp; &nbsp; i: integer;<br />
&nbsp; &nbsp; ov: OleVariant;<br />
&nbsp; &nbsp; iDisp: IDispatch;<br />
&nbsp; &nbsp; iColl: IHTMLElementCollection;<br />
&nbsp; &nbsp; iInputElement: IHTMLInputElement;<br />
&nbsp; &nbsp; accINI : TIniFile;<br />
&nbsp; begin<br />
&nbsp; &nbsp; accINI := TIniFile.Create(ExtractFilePath(Application.EXEName) + 'acc.ini');<br />
&nbsp; &nbsp; WebBrowser1.ControlInterface.Document.QueryInterface(IHtmlDocument2, iDoc);<br />
&nbsp; &nbsp; &nbsp; if not assigned(iDoc) then begin<br />
&nbsp; &nbsp; &nbsp; &nbsp; ShowMessage(' !!!??? Nothing dowloaded ... ');<br />
&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br />
&nbsp; &nbsp; &nbsp; end;<br />
&nbsp; ov := 'INPUT';<br />
&nbsp; IDisp := iDoc.all.tags(ov);<br />
&nbsp; &nbsp; if assigned(IDisp) then begin<br />
&nbsp; &nbsp; &nbsp; IDisp.QueryInterface(IHTMLElementCollection, iColl);<br />
&nbsp; &nbsp; if assigned(iColl) then begin<br />
&nbsp; &nbsp; &nbsp; for i := 1 to iColl.Get_length do begin<br />
&nbsp; &nbsp; &nbsp; &nbsp; iDisp := iColl.item(pred(i), 0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; iDisp.QueryInterface(IHTMLInputElement, iInputElement);<br />
&nbsp; &nbsp; if assigned(iInputElement) then begin<br />
&nbsp; &nbsp; if iInputElement.Get_name = 'ctl00$ctl00$cpMain$cpMain$LoginBox$Email_Textbox'<br />
//user account e-mail<br />
&nbsp; &nbsp; &nbsp; then iInputElement.Set_value(accINI.ReadString('email','em1',''));<br />
&nbsp; &nbsp; if iInputElement.Get_name = 'ctl00$ctl00$cpMain$cpMain$LoginBox$Password_Textbox'<br />
// password<br />
&nbsp; &nbsp; &nbsp; then iInputElement.Set_value(accINI.ReadString('password','psd1',''));<br />
&nbsp;//Submit Button<br />
&nbsp; &nbsp;  if iInputElement.Get_name = 'dlb'<br />
&nbsp; &nbsp; &nbsp; then iInputElement.Get_form.submit;<br />
// Show the Titel of the currently active Webpage in the titlebar<br />
&nbsp; &nbsp; &nbsp; Caption := Webbrowser1.OleObject.Document.Title<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br />
&nbsp; &nbsp; &nbsp; &nbsp; end;<br />
&nbsp; &nbsp; &nbsp; end;<br />
&nbsp; &nbsp; end;<br />
&nbsp; cur_user.Text := accINI.ReadString('email','em1','');<br />
&nbsp; accINI.Free;<br />
&nbsp; WebBrowser1.Navigate('http://MYOTHERSITE.com/');&nbsp; &nbsp; &nbsp; &nbsp; // here is where my wall is... the above procedure &quot;WebBrowser1NavigateComplete2&quot; I can ot figure how to recall it and use it here to force a &quot;wait til page fully loads&quot;<br />
&nbsp; end;<br />
<br />
procedure TForm1.opt_exitClick(Sender: TObject);<br />
&nbsp; begin<br />
&nbsp; &nbsp; Application.Terminate;<br />
&nbsp; end;<br />
<br />
end.</pre><br />
Thank you all.</div> ]]></content:encoded>
			<category domain="http://www.daniweb.com/forums/forum124.html">Pascal and Delphi</category>
			<dc:creator>casper_wang</dc:creator>
			<guid isPermaLink="true">http://www.daniweb.com/forums/thread231990.html</guid>
		</item>
	</channel>
</rss>
