How to use a TWebbrowser to post some stuff (code is almost complete)

Hi guyz!!

Using a TWebbrowser I fail to implement a button click right after some fields are filled in. This is the code(from swissdelphi) I use to fill in some fields and now I'd like to click a button in addition. The buttons sourcecode I dropped under the code segment of my app.



function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
  i, j: Integer;
  FormItem: Variant;
begin
  Result := False;
  //no form on document
  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
  begin
    Exit;
  end;
  //count forms on document
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
  begin
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);
    for j := 0 to FormItem.Length - 1 do
    begin
      try
        //when the fieldname is found, try to fill out
        if FormItem.Item(j).Name = FieldName then
        begin
          FormItem.Item(j).Value := Value;
          Result := True;
        end;
      except
        Exit;
      end;
    end;
  end;
end;


//When the document is complete try to fill out the field homepage with the url
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
if FillForm(WebBrowser1, 'TopicTitle', 'Experts Exchange Rockzz!') = False then
    ShowMessage('Error. Field not available or no Form found.');
    if FillForm(WebBrowser1, 'TopicDesc', 'Like H*ll!!') = False then
    ShowMessage('Error. Field not available or no Form found.');
    if FillForm(WebBrowser1, 'Post', 'They always do!') = False then
    ShowMessage('Error. Field not available or no Form found.');
  end;


This is the sourcecode from the page Im posting to. (the button I want to click).
<input type="submit" name="submit" value="Plaats een nieuw onderwerp" tabindex="7" class="button" accesskey="s" />


So can anyone implement a button click on that button after the fields are filling in? I managed to do so without a TWebbrowser but I fail to do so with a TWebbrowser. All points go to  him who completes this code. Let me know if you need some information more okay?

My regards and max respect!

PeterdeB
PeterdeBAsked:
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.

HypoviaxCommented:
Accesskey??

I am not sure about this, but is an accesskey like a short-cut key? Like pressing ctrl-s or something?

If so i know how to click that button! However, i need to know whether my understanding is correct and what keys need to be pressed.

Regards,

Hypoviax
0
PeterdeBAuthor Commented:
Hi Hypoviax!

I have really no idea what it represents I only noticed that the button code differed from buttons which I COULD press in order to submit something. That's why I posted the buttons source code, I'm not familiar with it at all. Would you please post your answer then I'll test it right away to see if it works ok?

My regards and respect and tnx for replying!

PeterdeB
0
HypoviaxCommented:
Well, the trouble is if my theory is right then it is some form of shortcut key, in which case i don't really know what the combination is (ctrl-s, alt-s etc). If i know the combination then you can use keyboard events, in effect pressing that combination.

I will try some of the html to see if is what i think it is then i will post the code.

Regards,

Hypoviax
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

HypoviaxCommented:
I am right:

http://www.cs.tut.fi/~jkorpela/forms/accesskey.html

Ok try this then:

 keybd_event(ord('S'),  MapvirtualKey( ord('S'), 0 ), 0, 0 );  //S key down
 keybd_event(ord('S'),  MapvirtualKey( ord('S'), 0 ), KEYEVENTF_KEYUP, 0); //S key up

For this to work the webbrowser must not lose focus. In otherwords, the webbrowser must have focus when you call the procedure to click the button. (webbrowser1.setfocus; RUN CODE)

regards,

Hypoviax
0
HypoviaxCommented:
unction FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
  i, j: Integer;
  FormItem: Variant;
begin
  Result := False;
  //no form on document
  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
  begin
    Exit;
  end;
  //count forms on document
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
  begin
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);
    for j := 0 to FormItem.Length - 1 do
    begin
      try
        //when the fieldname is found, try to fill out
        if FormItem.Item(j).Name = FieldName then
        begin
          FormItem.Item(j).Value := Value;
          Result := True;
        end;
      except
        Exit;
      end;
    end;
     keybd_event(ord('S'),  MapvirtualKey( ord('S'), 0 ), 0, 0 );  //S key down
     keybd_event(ord('S'),  MapvirtualKey( ord('S'), 0 ), KEYEVENTF_KEYUP, 0); //S key up
  end;
end;

Maybe in like that. You will have to test as i don't have the form ;-)

Regards,

Hypoviax
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
HypoviaxCommented:
Sorry hang on. You need to press alt-s not just s so the code is:

keybd_event(vk_MENU,  MapvirtualKey( vk_MENU), 0 ), 0, 0 );  //Alt key down
     keybd_event(ord('S'),  MapvirtualKey( ord('S'), 0 ), 0, 0); //S key down
keybd_event(vk_MENU,  MapvirtualKey( vk_MENU), 0 ), KEYEVENTF_KEYUP, 0);//alt up
     keybd_event(ord('S'),  MapvirtualKey( ord('S'), 0 ), KEYEVENTF_KEYUP, 0); //s up

Hypoviax
0
HypoviaxCommented:
and get rid of those brackets next to vk_MENU (after mapvirtualkey) - my mistake

Hypoviax
0
PeterdeBAuthor Commented:
Mister Hypoviax!! You rock! I just posted my message to my board with a single button click jieeehaaahhh!!!

A very big thank you! I implemented the setfocus and right after that it succeeded!!

My regards and max respect!!

PeterdeB
0
HypoviaxCommented:
I am glad i could help. If you need assistance with anything else related to this solution post it here

Regards,

Hypoviax
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.