I have an application that loads a web page through TWebBrowser, and on this page I have some HTML inputs. I want to change the input value and set the caret position to the end.
This is what I have at the moment:
procedure SetInputValue(Document : IHTMLDocument2; const ElementId, NewValue : String); var Doc : IHTMLDocument3; El : IHTMLElement; begin Doc := Document as IHTMLDocument3; if Assigned(Doc) then begin El := Doc.getElementById(ElementId); if Assigned(El) then begin if El.tagName = 'INPUT' then (El as IHTMLInputElement).Value := NewValue; (El as IHTMLInputElement).select; end; end; end;
This piece of code sets the input value and selects the text part. I know the IHTMLInputTextElement2 interface , but is only available from IE9
source share