TWebBrowser, how to set the caret position to the end of the INPUT field (text) in IE8

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

+4
source share
1 answer

You must use IHTMLTxtRange

 var Tr: IHTMLTxtRange; Tr := (El as IHTMLInputElement).createTextRange; Tr.collapse(true); Tr.moveEnd('character', Length(NewValue)); Tr.moveStart('character', Length(NewValue)); Tr.select(); 
+6
source

Source: https://habr.com/ru/post/1393197/


All Articles