Forum > LCL

TEdit's Autoselect

(1/3) > >>

Weitentaaal:
Hello Guys,

i wanted to do following: When the User clicks in a certain field(TEdit), the whole text in the field should be selected.

i tried:

-> Working with SelLength and SelStart (no effect):


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TMyClass.TxEnter(Sender: TObject);begin   Tx.SelStart:= 0;   Tx.SelLength:= Length(Tx.Text);end; 
-> The Porperty "Autoselect" (Standard set to True), but i had no effect on the Edit either

-> The Function SelectAll (no effect again)


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TMyClass.TxEnter(Sender: TObject);begin   Tx.SelectAll;end; 
found out that the "SelectAll" Function and the "SelStart" and "SelLength" Functions only work in the OnClick event handler. But the Problem here is that i wanted to create a shared handler for this function and in some fileds i already have code in the onClick event.

So back to the AutoSelect Property. Got it checked in the Object inspector but with no effect. Could someone help me ou please ? thanks in advance !

ASerge:

--- Quote from: Weitentaaal on January 25, 2022, 04:33:09 pm ---i wanted to do following: When the User clicks in a certain field(TEdit), the whole text in the field should be selected.

--- End quote ---
Example. In new form I appended two Edits, a timer and entered this code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Edit1Enter(Sender: TObject); // One event for both editsbegin  Timer1.Enabled := True;end; procedure TForm1.FormCreate(Sender: TObject);begin  Timer1.Interval := 50;  Timer1.Enabled := False;end; procedure TForm1.Timer1Timer(Sender: TObject);begin  Timer1.Enabled := False;  if ActiveControl is TEdit then    TEdit(ActiveControl).SelectAll;end;

Weitentaaal:
looks good ! thanks !

is this only possible with Timers ?

Zvoni:
Maybe something you missed for the AutoSelect-Property of TEdit:

--- Quote ---If True, the edit control will select all its text when it receives focus or when the Enter key is pressed

--- End quote ---

loaded:
For me it works just fine.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Edit1Click(Sender: TObject);begin  TEdit(sender).SelectAll;end;  

Navigation

[0] Message Index

[#] Next page

Go to full version