逃学威龙5国语完整版:请教一下delphi的MSHTML的问题,本来想给100分的,可是小弟只有27分!!

来源:百度文库 编辑:高考问答 时间:2024/05/11 03:58:36
请教一下delphi的MSHTML的问题
http://xxxxflashboy.zj.com/TEST.rar
这一个是测试的程序
当获取www.163.com时,这几个函数都有错误
doc.Body.offsetwidth;
doc.Body.offsetHeight;
doc.Body.getAttribute('offsetwidth', 0);
doc.Body.getAttribute('offsetHeight', 0);
doc.Body.getAttribute('Scrolltop', 0);
doc.Body.getAttribute('scrollLeft', 0);
当获取www.sina.com.cn,www.sohu.com,又正确了
是不是IHTMLDocument2、还是MSHTML不支持?
procedure TForm1.Button2Click(Sender: TObject);
var
Doc: IHTMLDocument2;
begin
Doc := WebBrowser1.Document as IHTMLDocument2;
edit2.Text := inttostr(doc.Body.offsetwidth);
edit3.Text := inttostr(doc.Body.offsetHeight);
edit4.Text := inttostr(doc.Body.offsetTop);
end;

MSHTML把HTML页面中的元素封装成了IHTMLInputElement、 IHTMLInputButtonElement、IHTMLInputTextElement、IHTMLTextAreaElement、IHTMLTitleElement、IHTMLFormElement等等组件接口。

在程序中可以通过MSHTML提供的IHTMLDocument2接口得到整个Document对象,IHTMLElementCollection接口得到所有页面元素的集合,通过该接口的Item方法可以得到具体的某个组件,然后设置和读取该组件的属性值。

1. 打开某个页面:

web.Navigate(ExtractFilePath(Application.ExeName) + 'Template/login.html');

2. 取出页面中某个HtmlElement的Value属性值:

function GetValueByElementName(web: TWebBrowser; elementName: string; index: integer): string;

begin

result := (((web.Document as IHTMLDocument2).body.all as

IHTMLElementCollection).item(elementName, index) as IHTMLInputElement

).value

end;

3. 给HtmlElement设置Value属性

procedure SetValueTextAreaName(web: TWebBrowser; elementName, value: string;index: integer);

begin

(((web.Document as IHTMLDocument2).body.all as

IHTMLElementCollection).item(elementName, index) as IHTMLTextAreaElement

).value := value;

end;

4. 判断页面执行结果是否成功

因为Web应用中如果出错的一般是采用错误页面的方式呈现给最终用户,所以我们也无法抓到Http错误,只能通过在webBeforeNavigate2事件中将URL参数记录到全局变量中, 然后在webDocumentComplete事件中根据URL参数和全局变量中的URL参数来判断执行结果是否正确.

.................................................................................................
页面限制,就说这些。其他不太清楚的查查资料好了。