was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

33 Visitors Online


 
...HTML Formulare mit TWebBrowser automatisch ausfüllen lassen?
Autor: Simon Grossenbacher
Homepage: http://www.swissdelphicenter.ch
[ Tip ausdrucken ]  

Tip Bewertung (62):  
     


{ To test this code put a TWebBrowser and A TButton component on the form }


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, 'homepage', 'http://www.swissdelphicenter.ch') = False then 
    
ShowMessage('Error. Field not available or no Form found.');
end;

// Show the Webbrowser-Progress in Label1 
procedure TForm1.WebBrowser1ProgressChange(Sender: TObject; Progress, ProgressMax: Integer); 
begin 
  if 
ProgressMax = 0 then 
  begin 
    
label1.Caption := ''; 
    Exit; 
  end
  try 
    if 
(Progress <> -1) and (Progress <= ProgressMax) then 
      
label1.Caption := IntToStr((Progress * 100) div ProgressMax) + '% loaded...' 
    else 
      
label1.Caption := ''; 
  except 
    on 
EDivByZero do Exit; 
  end
end


//For example you can load the page /en/addtip.php to the TWebBrowser 
//When the document is Complete the form where you can put your homepage 
//address is filled out 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
  
Webbrowser1.Navigate('http://www.swissdelphicenter.ch/en/addtip.php'); 
  // Show the Titel of the currently active Webpage in the titlebar 
  // Den Titel der aktuellen Webseite in der Titeleiste anzeigen 
  
Caption := Webbrowser1.OleObject.Document.Title; 
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


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