我在MSDN上找了些资料,可用DELPHI做出来却不行,下面是我的代码: ButtonName:='Button1'; Buttonindex:=0; IButtonDispatch:=(Web.Document as IHTMLDocument2).all.item(ButtonName,Buttonindex); if Assigned(IButtonDispatch) then begin hr:=IButtonDispatch.QueryInterface(IID_IHTMLElement,pElem); if SUCCEEDED(hr) then begin hr:=pElem.QueryInterface(IConnectionPointContainer,IHTML); if SUCCEEDED(hr) then //IHTMLElementDispIHTMLElement2Disp begin if SUCCEEDED(IHTML.FindConnectionPoint(DIID_HTMLElementEvents2 ,HTMLPoint)) then //上一行总是不成功! begin HTMLPoint.Advise(Self,HTMLCook); messagebox(0,'OK','df',MB_OK); end else begin Messagebox(0,'fail','dsf',MB_OK); end; end; end; end; 运行后,总是出现“fail”对话框 也就是IHTML.FindConnectionPoint(DIID_HTMLElementEvents2 ,HTMLPoint)这一行总是失败,请高手帮帮忙!!!
ButtonName:='Button1';
Buttonindex:=0;
IButtonDispatch:=(Web.Document as IHTMLDocument2).all.item(ButtonName,Buttonindex);
if Assigned(IButtonDispatch) then
begin
hr:=IButtonDispatch.QueryInterface(IID_IHTMLElement,pElem);
if SUCCEEDED(hr) then
begin
hr:=pElem.QueryInterface(IConnectionPointContainer,IHTML);
if SUCCEEDED(hr) then //IHTMLElementDispIHTMLElement2Disp
begin
if SUCCEEDED(IHTML.FindConnectionPoint(DIID_HTMLElementEvents2 ,HTMLPoint)) then
//上一行总是不成功!
begin
HTMLPoint.Advise(Self,HTMLCook);
messagebox(0,'OK','df',MB_OK);
end
else
begin
Messagebox(0,'fail','dsf',MB_OK);
end;
end;
end;
end;
运行后,总是出现“fail”对话框
也就是IHTML.FindConnectionPoint(DIID_HTMLElementEvents2 ,HTMLPoint)这一行总是失败,请高手帮帮忙!!!