TWEBBROWSER Come impostare la posizione di Caret fino alla fine del campo Input (Testo) su IE8

StackOverflow https://stackoverflow.com/questions/9020687

  •  14-11-2019
  •  | 
  •  

Domanda

Ho un'applicazione che carica una pagina web tramite Twebbrowser e in questa pagina ho alcuni ingressi HTML.Quello che voglio è cambiare il valore di un ingresso e impostare la posizione di caret fino alla fine.

Questo è ciò che ho al momento:

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;
.

Questo pezzo di codice imposta il valore di ingresso e evidenzia la porzione di testo. Sono consapevole del Ihtmlinputtextelement2 Interfaccia Ma è disponibile solo da IE9

È stato utile?

Soluzione

You should 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();   
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top