Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi ExecuteScript?! (https://www.delphipraxis.net/21124-executescript.html)

Evian 28. Apr 2004 10:16


ExecuteScript?!
 
Ich habe bei Swissdelphicenter einen Code gefunden um JS Formulare
im Internet automatisch ausfüllen zu können. -> URL

Das Problem ist nur, dass meine IDE den Befehl ExecuteScript nicht kennt,
obwohl ich alle Units eingebunden habe. Hat Jemand eine Ahnung, woran das
liegen könnte?! Ich nutze zur Zeit zu Testzwecken Delphi 7 [Pro]

gruss


Evian

citybreaker 28. Apr 2004 11:06

Re: ExecuteScript?!
 
Öh, hast du shellapi bei uses eingebunden?

Evian 28. Apr 2004 11:18

Re: ExecuteScript?!
 
Mein Code ist follgender:

Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, MSHTML_TLB, SHDocVw_TLB, ShDocVW, ShellAPI, StdCtrls, OleCtrls;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
  procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;


implementation

{$R *.dfm}
procedure FillInGMXForms(WB: ShDocVW_TLB.IWebbrowser2; IDoc1: IHTMLDocument2;
  Document: Variant; AKennung, APasswort: string);
const
  IEFields: array[1..4] of string = ('INPUT', 'text', 'INPUT', 'password');
var
  IEFieldsCounter: Integer;
  i: Integer;
  m: Integer;
  ovElements: OleVariant;
begin
  if Pos('GMX - Homepage', Document.Title) <> 0 then

    while WB.ReadyState <> READYSTATE_COMPLETE do
      Application.ProcessMessages;

  // count forms on document and iterate through its forms
  IEFieldsCounter := 0;
  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
        // if input fields found, try to fill them out
        if (ovElements.item(i).tagName = IEFields[1]) and
          (ovElements.item(i).type = IEFields[2]) then
        begin
          ovElements.item(i).Value := AKennung;
          Inc(IEFieldsCounter);
        end;

        if (ovElements.item(i).tagName = IEFields[3]) and
          (ovElements.item(i).type = IEFields[4]) then
        begin
          ovElements.item(i).Value := APasswort;
          Inc(IEFieldsCounter);
        end;
      except
        // failed...
      end;
    end; { for i...}
  end; { for m }
  // if the fields are filled in, submit.
  if IEFieldsCounter = 3 then ExecuteScript(iDoc1, 'document.login.submit()',
      'JavaScript');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  IDoc1: IHTMLDocument2;
  Web: ShDocVW_TLB.IWebBrowser2;
begin
  Webbrowser1.Navigate('http://www.gmx.ch');
  while Webbrowser1.ReadyState <> READYSTATE_COMPLETE do
    Application.ProcessMessages;
  Webbrowser1.Document.QueryInterface(IHTMLDocument2, iDoc1);
  Web := WebBrowser1.ControlInterface;
  FillInGMXForms(Web, iDoc1, Webbrowser1.Document, 'user@gmx.net', 'pswd');
end;
end.
und die Fehlermeldung:
[Fehler] Unit1.pas(72): Undefinierter Bezeichner: 'ExecuteScript'

in welcher Unit genau, soll denn "ExecuteScript" drin sein?!
Und könntest Du(oder jemand anderes) die unit mal hochladen?!


gruss

Evian

citybreaker 28. Apr 2004 11:23

Re: ExecuteScript?!
 
Ähm bei dem oberen link steht noch folgene funktion bei names "excutescript".
Tu die mal mit in Unit1 packen.

Delphi-Quellcode:
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;

Evian 28. Apr 2004 11:25

Re: ExecuteScript?!
 
oh man *auf den kopf hau* ... bin ich ein Obertrottel!!!

*g* -> öhm, können wir so tun, als hät ich nie gefragt?!


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:07 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz