Solved

TWebBrowser and Submit.Form issue?

Posted on 2004-10-26
272 Views
Last Modified: 2010-05-18
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
0
Question by:Wayne Barron
    3 Comments
     
    LVL 17

    Accepted Solution

    by:
    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
     
    LVL 30

    Author Comment

    by:Wayne Barron
    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
     
    LVL 17

    Expert Comment

    by:geobul
    The pleasure was mine :-)
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: From Zero to Hero with Nodejs & MongoDB

    Interested in Node.js, but don't know where to start or how to learn it properly? Confused about how the MEAN stack pieces of MongoDB, Expressjs, Angularjs, and Nodejs fit together? Or how it's even possible to run JavaScript outside of the browser?

    Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now