whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

42 Visitors Online


 
...submit a Form in TWebbrowser with an image submit button?
Autor: Jailbird
Homepage: http://www.tooldesign.ch
[ Print tip ]  

Tip Rating (20):  
     


{
 If you have a webpage with a Form on it, but the submit - button is an image,
 you can use this code (using a TWebBrowser)
}

{
 Falls du eine Webpage mit einem Formular hast,
 bei welchem der Submit-Knopf ein Bild ist,
 dann kannst du diesen Code benutzen (sowie ein TWebBrowser)
}

uses
  
MSHTML;

var
  
iDoc: IHtmlDocument2;
  i: integer;
  ov: OleVariant;
  iDisp: IDispatch;
  iColl: IHTMLElementCollection;
  InputImage: HTMLInputImage;
begin
  
WebBrowser1.ControlInterface.Document.QueryInterface(IHtmlDocument2, iDoc);
  if not Assigned(iDoc) then
  begin
    
Exit;
  end;
  ov := 'INPUT';
  iDisp := iDoc.all.tags(ov);
  if Assigned(IDisp) then
  begin
    
IDisp.QueryInterface(IHTMLElementCollection, iColl);
    if Assigned(iColl) then
    begin
      for 
i := 1 to iColl.Get_length do
      begin
        
iDisp := iColl.item(pred(i), 0);
        iDisp.QueryInterface(HTMLInputImage, InputImage);
        if Assigned(InputImage) then
        begin
          if 
InputImage.Name = 'submit' then
          
// if the name is submit / falls der name submit lautet
          
begin
            
InputImage.Click;  // click it / klick es
          
end;
        end;
      end;
    end;
  end;
end;

// 2.

procedure TForm1.Button1Click(Sender: TObject);
var
  
i: Word;
  Document: IHtmlDocument2;
  str: string;
begin
  
// Schleife über alle Bilder im Webbrowser
  
for i := 0 to WebBrowser1.OleObject.Document.Images.Length - 1 do
  begin
    
Document := WebBrowser1.Document as IHtmlDocument2;
    // URL auslesen
    
Str := (Document.Images.Item(i, 0) as IHTMLImgElement).Href;
    // Dateiname des Bildes überprüfen
    
if Pos('submit_icon.gif', str) <> 0 then
    begin
      
((Document.Images.Item(i, 0) as IHTMLImgElement) as IHTMLElement).Click;
    end;
  end;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners