2010-05-23 82 views
0

以下程序在2個地方(第39和45行)返回error : e2035 not enough actual parameters,並且不進行編譯。有人可以幫我嗎? 我可以在這裏放置0或null來代替參數嗎?沒有足夠的實際參數?

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. 
+0

爾,線39是 「MYPASSWORD:= '密碼';」 45是空行。您能否請您提出違規的評論? – 2010-05-23 12:32:48

+1

@Frank Shearar:這是對Navigate的調用,它需要5個參數(不是3或1)。 – 2010-05-23 12:36:21

回答

5

您可以在variants.pas上使用任何虛擬變量或「EmptyParam」變量;

MyBrowser.Navigate(loginURL,0,EmptyParam,EmptyParam,EmptyParam); 
+0

仍然無法登錄到Gmail取代登錄網址:loginURL:='javascript:var Email = document.getElementById(''''); Email.value ='''+ myUserName +'''; var Password = document。 getElementById(''Password''); Password.value ='''+ myPassword +'''; var SignIn = document.getElementById(''signIn''); SignIn.click();';請幫助 – 2010-05-23 14:21:33

+0

@omair - 您以前的「loginURL」是正確的(AFAICS),但您必須等待瀏覽器完成加載「https://www.google.com/accounts」才能運行腳本。爲什麼不使用TWebBrowser,它有一個「OnDocumentComplete」事件。此外,我不確定您可以使用「navOpenInNewWindow」導航兩次,請參閱msdn頁面的底部('IWebBrowser2 :: Navigate Method')http://msdn.microsoft.com/en-us/library /aa752133%28VS.85%29.aspx) – 2010-05-23 16:08:04

2

導航的簽名是

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

,這樣你就需要更多的參數。有關官方MSDN文檔,請參閱MSDN

可以編寫

var 
    PostData: OleVariant; 

PostData := 0; 
MyBrowser.Navigate('http://www.gmail.com',flags,'_blank', PostData, 0); 
+0

仍然無法登錄到Gmail,取而代之的登錄網址爲:loginURL:='javascript:var Email = document.getElementById(''Username''); Email.value ='''+ myUserName +'''; var Password = document.getElementById(''Password''); Password.value ='''+ myPassword +'''; var SignIn = document.getElementById(''signIn''); SignIn。點擊();'; 請幫忙 – 2010-05-23 14:20:29

+0

@omair iqbal:也許WebBrowser根本不會接受javascript:「URL」。畢竟,您的javascript:「URL」引用了當前加載的文檔,但是,也許只要導航過程是確認性的,就沒有活動文檔。 – 2010-05-23 14:55:29

2

使用一個TWebBrowser或通過EmptyParam像(Delphi源)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; 
相關問題