次のコードでは、いくつかのエラーが発生します。そのうちの 2 つは次のとおりです。
- [エラー] Unit1.pas(28): 宣言されていない識別子: 'WebBrowser1NavigateComplete2'
- [エラー] Unit1.pas(34): 宣言されていない識別子: 'WebBrowser1DocumentComplete'
それらが「用途」セクションで宣言されていないかどうか疑問に思っています。なぜそれがコンパイルされないのか、誰にも分かりません。Delphi ヘルプからコードを取得しました。
また、「メッセージ ボックス」や完了の「ビープ音」も表示されません。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, MSHTML, activex;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
WebBrowser1: TWebBrowser;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
CurDispatch: IDispatch; {save the interface globally }
implementation
{$R *.dfm}
procedure TForm1.WebBrowser1NavigateComplete2(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
begin
if CurDispatch = nil then
CurDispatch := pDisp; { save for comparison }
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
begin
if (pDisp = CurDispatch) then
begin
Beep; {the document is loaded, not just a frame }
showmessage('download complete');
CurDispatch := nil; {clear the global variable }
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('www.google.com');
end;
end.