Einzelnen Beitrag anzeigen

Speedfighter

Registriert seit: 12. Jun 2008
9 Beiträge
 
#13

Re: Webbrowser Radiobutton ansprechen

  Alt 12. Jun 2008, 18:51
Hier mein Kompletter Quelltext

Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, SHDocVw, XPMan, ExtCtrls;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    GroupBox1: TGroupBox;
    LabeledEdit1: TLabeledEdit;
    LabeledEdit2: TLabeledEdit;
    XPManifest1: TXPManifest;
    LabeledEdit3: TLabeledEdit;
    LabeledEdit4: TLabeledEdit;
    LabeledEdit5: TLabeledEdit;
    LabeledEdit6: TLabeledEdit;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

function WB_FindFieldByValue(WebBrowser: TWebBrowser; FieldType, FieldValue: string; var Field: TPoint): boolean;
var
  i, j: Integer;
  FormItem: Variant;
begin
  Result := False;
  if Assigned(WebBrowser.Document) then
  begin
  if WebBrowser.OleObject.Document.all.tags('FORM').Length <> 0 then
    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
          if (FormItem.Item(j).Value = FieldValue) and
            (FormItem.Item(j).Type = FieldType) then
          begin
            Field.x := i;
            Field.Y := j;
            Result := True;
            Exit;
          end;
        except
         // Exit;
        end;
      end;
    end;
  end;
end;

function WB_SetRadioCheckboxField(WebBrowser: TWebBrowser; FieldType, FieldValue: string; Checked: boolean): Boolean;
var
  Field: TPoint;
begin
  Result := WB_FindFieldByValue(WebBrowser, FieldType, FieldValue, Field);
  if Result then
  try
    WebBrowser.OleObject.Document.forms.Item(Field.x).Item(Field.y).Checked := Checked;
    Result := True;
  except
    Result := False;
  end;
end;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.OleObject.document.forms.item(0).elements.item('person_vorname').value:='Eric';
WebBrowser1.OleObject.document.forms.item(0).elements.item('person_nachname').value:='Abt';
WebBrowser1.OleObject.document.forms.item(0).elements.item('adresse_strasse').value:='Knesebeckstrasse';
WebBrowser1.OleObject.document.forms.item(0).elements.item('adresse_postleitzahl').value:='57639';
WebBrowser1.OleObject.document.forms.item(0).elements.item('person_email').value:='Spende@discardmail.com';
WebBrowser1.OleObject.document.forms.item(0).elements.item('adresse_hausnummer').value:='43';
WebBrowser1.OleObject.document.forms.item(0).elements.item('adresse_ort').value:='Oberdreis';
WebBrowser1.OleObject.document.forms.item(0).elements.item('kreditkarte_nummer').value:=LabeledEdit1.text;
WebBrowser1.OleObject.document.forms.item(0).elements.item('kreditkarte_inhaber').value:=LabeledEdit2.text;
WebBrowser1.OleObject.document.forms.item(0).elements.item('kreditkarte_kpn').value:=LabeledEdit6.text;
WB_SetRadioCheckboxField(WB, 'checkbox', 'allgemein_datenschutzerklaerung', True);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
webbrowser1.Navigate('https://www.aerzte-ohne-grenzen.de/Spenden/Online.php');
end;

end.
  Mit Zitat antworten Zitat