views:

245

answers:

3

The following program returns error : e2035 not enough actual parameters in 2 places (lines 39 and 45) and is not compiling. Can someone please help me out? Can I put 0 or null in place of parameters here?

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,ComObj,shdocvw,activex, StdCtrls;

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
  var
   mybrowser : iwebbrowser2;
  myUserName,
myPassword,loginURL : string;
    Flags: OleVariant;

begin
    Flags :=  navOpenInNewWindow;
     MyBrowser := CreateOleObject('InternetExplorer.Application') as IWebBrowser2;
MyBrowser.Navigate('http://www.gmail.com',flags,'_blank');

myUserName := 'UserName';
myPassword := 'password';
loginURL:='javascript:var Email = document.getElementById(''Email'');Email.value=''' + myUserName + ''';var Password = document.getElementById(''Passwd'');Password.value=''' + myPassword + ''';var SignIn = document.getElementById(''signIn'');SignIn.click();';

MyBrowser.Navigate(loginURL);

end;

end.
+4  A: 

You can use any dummy variable or the "EmptyParam" variable on variants.pas;

MyBrowser.Navigate(loginURL,0,EmptyParam,EmptyParam,EmptyParam);
Sertac Akyuz
still cant login to gmail replaced login url to : loginURL:='javascript:var Email = document.getElementById(''Username'');Email.value=''' + myUserName + ''';var Password = document.getElementById(''Password'');Password.value=''' + myPassword + ''';var SignIn = document.getElementById(''signIn'');SignIn.click();'; please help
Omair Iqbal
@omair - Your previous "loginURL" was correct (AFAICS), but you have to wait for the browser to complete loading "https://www.google.com/accounts" before you can run your script. Why don't you use a TWebBrowser, it has an "OnDocumentComplete" event. Also I'm not sure you'll be able to navigate twice with "navOpenInNewWindow", see the bottom of the page at msdn ('IWebBrowser2::Navigate Method' http://msdn.microsoft.com/en-us/library/aa752133%28VS.85%29.aspx )
Sertac Akyuz
+2  A: 

The signature of Navigate is

    procedure Navigate(const URL: WideString; const Flags: OleVariant;
                   const TargetFrameName: OleVariant; var PostData: OleVariant;
                   const Headers: OleVariant); safecall;

so you do need more parameters. For the official MSDN documentation, see MSDN.

You can write

var
  PostData: OleVariant;

PostData := 0;
MyBrowser.Navigate('http://www.gmail.com',flags,'_blank', PostData, 0);
Andreas Rejbrand
still cant login to gmail replaced login url to : loginURL:='javascript:var Email = document.getElementById(''Username'');Email.value=''' + myUserName + ''';var Password = document.getElementById(''Password'');Password.value=''' + myPassword + ''';var SignIn = document.getElementById(''signIn'');SignIn.click();'; please help
Omair Iqbal
@omair iqbal: Maybe the WebBrowser simply will not accept a javascript: "URL". After all, your javascript: "URL" makes references to the currently loaded document, but, perhaps, as far as the Navigate procedure is concerend, there is no active document.
Andreas Rejbrand
+2  A: 

Use a TWebBrowser or pass EmptyParam like in (Delphi source) SHDocVw.pas:

procedure TWebBrowser.Navigate(const URL: WideString);
begin
  DefaultInterface.Navigate(URL, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
end;

procedure TWebBrowser.Navigate(const URL: WideString; const Flags: OleVariant);
begin
  DefaultInterface.Navigate(URL, Flags, EmptyParam, EmptyParam, EmptyParam);
end;

procedure TWebBrowser.Navigate(const URL: WideString; const Flags: OleVariant;
                               const TargetFrameName: OleVariant);
begin
  DefaultInterface.Navigate(URL, Flags, TargetFrameName, EmptyParam, EmptyParam);
end;

procedure TWebBrowser.Navigate(const URL: WideString; const Flags: OleVariant;
                               const TargetFrameName: OleVariant; var PostData: OleVariant);
begin
  DefaultInterface.Navigate(URL, Flags, TargetFrameName, PostData, EmptyParam);
end;

procedure TWebBrowser.Navigate(const URL: WideString; const Flags: OleVariant;
                               const TargetFrameName: OleVariant; var PostData: OleVariant;
                               const Headers: OleVariant);
begin
  DefaultInterface.Navigate(URL, Flags, TargetFrameName, PostData, Headers);
end;
François