Why do I get an access violation when setting the value of an IHTMLInputTextElement?

筅森魡賤 提交于 2019-12-11 03:26:49

问题


I get the following error:

Access Violation at address 0050AA07 in module "project1.exe". Read of address 00000000.

I'm trying to auto fill a form in TWebBrowser. It's just a field called 'login' on a form.

What does it mean? How do I solve it?

procedure TForm1.Button2Click(Sender: TObject);
var
  doc: IHTMLDocument2;
  frm: IHTMLFormElement;
  fld: IHTMLInputTextElement;
begin
  doc := webbrowser1.Document as IHTMLDocument2;
  frm := doc.forms.item(0, EmptyParam) as IHTMLFormElement;
  fld := frm.item('login', EmptyParam) as IHTMLInputTextElement;
  fld.value := 'someone';
end;

回答1:


It means you are dereferencing a pointer that is set to nil and the code that is attempting this illegal act is located at $0050AA07 in your process.

If you can't solve it from this, then if showed us the code we could tell you why your pointer is set to nil.



来源:https://stackoverflow.com/questions/4984116/why-do-i-get-an-access-violation-when-setting-the-value-of-an-ihtmlinputtextelem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!