Autor Beitrag
recall
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 449



BeitragVerfasst: So 21.12.03 01:12 
Hallo,

Ich würde mich gerne mittels TWebBrowser-Komponente bei:
mein-depot.dab-bank....p;time=1071963654484
anmelden. (Also nicht dass der User auf Anmelden klickt, sondern ich selber.) Nur leider finde ich keinen Ansatz ! Wie geht das ?

Viele Grüsse.
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: So 21.12.03 09:29 
Hi,

Habe etwas für dich gecoded :o
Damit kannst du im IE automatisch in den
"Depot-Manager" einloggen, falls die seite 'LoginBody' offen ist.
Dieser Code lässt sich rel. einfach auf einen TWebbrowser umschreiben
oder an deine Bedürfnisse anpassen.


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
uses
  MSHTML_TLB, ShellAPI;

// function to execute a script function

function ExecuteScript(doc: IHTMLDocument2; script: string; language: string): Boolean;
var
  win: IHTMLWindow2;
  Olelanguage: Olevariant;
begin
  if doc <> nil then
  begin
    try
      win := doc.parentWindow;
      if win <> nil then
      begin
        try
          Olelanguage := language;
          win.ExecScript(script, Olelanguage);
        finally
          win := nil;
        end;
      end;
    finally
      doc := nil;
    end;
  end;
end;

function LoginIE(Zugangsnummer, PIN, Identifier: string; ATitle : string = ''): Boolean;
type
  TIEFields = record
    tagName : String;
    fType : String;
    Name : String;
  end;
const
  MaxIEFields = 3;
  IEFields: array[1..MaxIEFields] of TIEFields = (
    (tagName : 'INPUT'; fType : 'text'; Name: 'authentificationnumberLogin'),
    (tagName : 'INPUT'; fType : 'password'; Name: 'pinLogin'),
    (tagName : 'INPUT'; fType : 'password'; Name: 'identifierLogin')
  );
var
  ShellWindow: IShellWindows;
  WB: IWebbrowser2;
  spDisp: IDispatch;
  IDoc1: IHTMLDocument2;
  Document: Variant;
  k, m, o: Integer;
  ovElements: OleVariant;
  i: Integer;
  IEFieldsCounter: Integer;
  IEFormName : array[1..MaxIEFields] Of String;
begin
  Result := Boolean(0);
  ShellWindow := CoShellWindows.Create;
  // Get the running instance of Internet Explorer
  for k := 0 to ShellWindow.Count do
  begin
    spDisp := ShellWindow.Item(k);
    if spDisp = nil then
      Continue;
    // QueryInterface determines if an interface can be used with an object
    spDisp.QueryInterface(iWebBrowser2, WB);
    IEFieldsCounter := 0;
    if WB <> nil then
    begin
      WB.Document.QueryInterface(IHTMLDocument2, iDoc1);
      if iDoc1 <> nil then
      begin
        WB := ShellWindow.Item(k) as IWebbrowser2;
        Document := WB.Document;
        // if Page title ok...
        if (Pos(ATitle, Document.Title) <> 0) or (ATitle = '') then
          // Count forms on document and iterate through its forms
          for m := 0 to Document.forms.Length - 1 do
          begin
            ovElements := Document.forms.Item(m).elements;
            // iterate through elements
            for i := ovElements.Length - 1 downto 0 do
            begin
              try
               Form1.mmoMemo1.Lines.Add(ovElements.item(i).name);
                // compare elements with our IEFormName array
                for o := 1 to 3 do
                // if input fields found, try to fill them out
                if (ovElements.item(i).tagName = IEFields[o].tagName) and
                   (ovElements.item(i).type = IEFields[o].fType) and
                   (ovElements.item(i).name = IEFields[o].Name) then
                  begin
                    case o of
                     1: ovElements.item(i).Value := Zugangsnummer;
                     2: ovElements.item(i).Value := PIN;
                     3: ovElements.item(i).Value := Identifier;
                    end;
                    IEFormName[o] := Document.forms.Item(m).name;
                    If (IEFormName[o] = '') then
                      IEFormName[o] := 'forms[' + IntToStr(m) + ']';
                    inc(IEFieldsCounter);
                  end;
              except
                // failed...
              end;
            end; { for i...}
          end;  { for m }
      end;  { idoc <> nil }
    end; { wb <> nil }
    // if the fields are filled in, submit.
    if (IEFieldsCounter = MaxIEFields) and (IEFormName[1] = IEFormName[2]) then
      begin
        ExecuteScript(iDoc1, 'document.' + IEFormName[1] + '.submit()', 'JavaScript');
        Result := Boolean(1);
      end;
  end;  { for k }
end;

procedure TForm1.btnButton1Click(Sender: TObject);
begin
  LoginIE('Zugangsnummer', 'PIN','Identifier','LoginBody');
end;
recall Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 449



BeitragVerfasst: So 21.12.03 09:59 
Wow... Danke !! :D