• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

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);
  AdminSubmit : IHTMLInputElement;
  MyDocument : IHTMLDocument3;
   MyDocument := AdminWeb.Document as IHTMLDocument3;
   if Assigned(MyDocument) then
   AdminSubmit := (MyDocument.getElementsByName('Admin_Login').item(0,'')as
end; end;


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

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.
Wayne Barron
Wayne Barron
  • 2
1 Solution

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
Wayne BarronAuthor 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.

The pleasure was mine :-)
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.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now