TWebBrowser and Submit.Form issue?

Hello All;

 I am using the following code to click the [Submit] button on my site.
VIA the TWebBrowser ( TEmbeddedWB).  This works great, except it has a problem?
After it click the [Submit] Button, and the next page opens, I get an
Exception. It is trying to [Submit] the page again.

  I have used this code before, and have never had this problem before.
And now ?? I do not know ??

Provided is the Code that I am using.
Below the Code will be the " Exception " that I received on the next page.

==+==+==+==+==+==+==++=+==+==+=++=+==+==+==
add to [Uses :  MSHTML_TLB; ]

procedure TProject1.AdminWebDocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
var
  AdminSubmit : IHTMLInputElement;
  MyDocument : IHTMLDocument3;
begin
   MyDocument := AdminWeb.Document as IHTMLDocument3;
   if Assigned(MyDocument) then
   begin
   AdminSubmit := (MyDocument.getElementsByName('Admin_Login').item(0,'')as
IHTMLInputElement);
   AdminSubmit.Form.Submit;
end; end;
==+==+==+==+==+==+==++=+==+==+=++=+==+==+==

Exception

---------------------------
Debugger Exception Notification
---------------------------
Project Project.exe raised exception class EAccessViolation with message
'Access violation at address 00483C79 in module 'Project.exe'. Read of
address 00000000'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help
---------------------------

It lands on
==+==+==+==+==+==+==
AdminSubmit.Form.Submit;
==+==+==+==+==+==+==

Any idea's on how to make this code work to where it only executes
When the " Username & Password " form is presented?
And not on pages that do not require it?

Thank you all in advance.
Carrzkiss
LVL 31
Wayne BarronAuthor, Web DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

geobulCommented:
Hi,

Try checking if that InputElement exists in the document:

   AdminSubmit := (MyDocument.getElementsByName('Admin_Login').item(0,'')as IHTMLInputElement);
   if Assigned(AdminSubmit) then  AdminSubmit.Form.Submit;

As far as I can see that is an event handler for your WebBrowser OnComplete event and it's being called for all pages you're navigating.

Regards, Geo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wayne BarronAuthor, Web DeveloperAuthor Commented:
Thank you so very much [Geobul];

Adding the
is assigned(AdminSubmit) then

right before -  AdminSubmit.Form.Submit;

Did the trick.

Once again, thank you very much.

Carrzkiss
0
geobulCommented:
The pleasure was mine :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.