Remplir une page HTML dans un TWebBrowser

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
begin
ShowMessage('Error. Field not available or no Form found.');
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');
end;
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour18/11/2001
VisualisationVu 2335 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Internet
Auteur de l'article
SwissDelphiCenter SwissDelphiCenter
connecté le 02/11/2011
329 articles dans la section
Contacter l'auteur