[Solved] How to unselect the text in a focused TEdit, programmatically lazarus / 31-LCL ---------------------------------------------------------------------- cdbc · 2024-11-25 16:58 Hi I'm having a 'Brain-fart'  I can't seem to figure out how to un-select the text in a focused TEdit, programmatically from within the containing form...?!? Any help will be greatly appreciated. Regards Benny ---------------------------------------------------------------------- ackarwow · 2024-11-25 17:07 Maybe Edit.SelLength:=0 will be sufficient? ---------------------------------------------------------------------- dsiders · 2024-11-25 17:12 Quote from: cdbc on November 25, 2024, 05:58:55 pmHi I'm having a 'Brain-fart'  I can't seem to figure out how to un-select the text in a focused TEdit, programmatically from within the containing form...?!? Any help will be greatly appreciated. Regards Benny TEdit.ClearSelection ---------------------------------------------------------------------- cdbc · 2024-11-25 17:35 Hi Sorry guys, neither of your suggestions worked... I'd like for the user to type onto the end of the pretext, but alas, when it's selected, the pretext just gets overwritten. I've also tried:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   edtMask.SelStart:= bcLengthUTF8(edtMask.Text);  edtMask.SelLength:= 0;or  edtMask.Perform(LM_KEYDOWN,VK_END,VK_END);  edtMask.Perform(LM_KEYUP,VK_END,VK_END);  Hmmm, what's next, to try... Regards Benny ---------------------------------------------------------------------- Bart · 2024-11-25 17:40 Quote from: dsiders on November 25, 2024, 06:12:12 pmTEdit.ClearSelection TEdit.ClearSelection: Removes the selected text from the edit control. I think that's not what TS wants. Bart ---------------------------------------------------------------------- Bart · 2024-11-25 17:42 Are you using a TMaskEdit? In that case: it'll always select at leas one character in the control when you type or tab into the control. Setting SelLength to zero should just work (also for a TMaskEdit). Bart ---------------------------------------------------------------------- cdbc · 2024-11-25 17:43 Hi Thanks Bart - No it's not and no it didn't... Plain ol' TEdit. Regards Benny ---------------------------------------------------------------------- ackarwow · 2024-11-25 17:43 Quote from: cdbc on November 25, 2024, 06:35:27 pmHi Sorry guys, neither of your suggestions worked... I'd like for the user to type onto the end of the pretext, but alas, when it's selected, the pretext just gets overwritten. I've also tried:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   edtMask.SelStart:= bcLengthUTF8(edtMask.Text);  edtMask.SelLength:= 0;or  edtMask.Perform(LM_KEYDOWN,VK_END,VK_END);  edtMask.Perform(LM_KEYUP,VK_END,VK_END);  Hmmm, what's next, to try... Regards Benny @Benny When do you call this code (what event)? ---------------------------------------------------------------------- cdbc · 2024-11-25 17:46 Hi QuoteWhen do you call this code (what event)?It gets called just after I assign the 'pretext' to edtMask.Text, in the 'change-handler' for edtMask... Regards Benny ---------------------------------------------------------------------- dsiders · 2024-11-25 17:55 Quote from: Bart on November 25, 2024, 06:40:28 pmQuote from: dsiders on November 25, 2024, 06:12:12 pmTEdit.ClearSelection TEdit.ClearSelection: Removes the selected text from the edit control. I think that's not what TS wants. Bart Doh. My bad. ---------------------------------------------------------------------- ackarwow · 2024-11-25 17:58 Quote from: cdbc on November 25, 2024, 06:46:26 pmHi QuoteWhen do you call this code (what event)?It gets called just after I assign the 'pretext' to edtMask.Text, in the 'change-handler' for edtMask... Regards Benny You can try to change Edit1.AutoSelect property (if checked) into 'false' and then in change handler add something like this: Edit1.SelStart:=length(Edit1.Text); (Edit1 is your TEdit) ---------------------------------------------------------------------- Bart · 2024-11-25 18:02 This code moves the caret to the end of the text and unselects everything in a TEdit Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Edit1.SelStart := MaxInt;  Edit1.SelLength := 0; Works fine for me. Bart ---------------------------------------------------------------------- cdbc · 2024-11-25 18:45 Hi @Bart, hmm - not so much here... :/ Through fiddling, I got it to work... I think  I ended up with this solution:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmWords.DelayedShow(aData: ptrint);  // edtMask.SelStart:=  bcLengthUTF8(edtMask.Text)begin  edtMask.SelStart:= aData;  edtMask.SelLength:= 0;end;  procedure TfrmWords.FormShow(Sender: TObject);begin  Application.QueueAsyncCall(@DelayedShow,bcLengthUTF8(e dtMask.Text));end; procedure TfrmWords.edtMaskChange(Sender: TObject);begin { 'Text' property is the safer bet, 'cause the wordcompletion could come from a lib }  if fStartsWith then lbxWords.Items.Text:= fwc.GetCompletedPrefix(edtMask.Text,false).Text { no is/as }  else fwc.GetWordList(lbxWords.Items,edtMask.Text,true,false,256);  if lbxWords.Items.Count > 0 then lbxWords.ItemIndex:= 0;end; Thank you for all of your suggestions... Regards Benny ---------------------------------------------------------------------- jamie · 2024-11-30 23:14 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Edit1Enter(Sender: TObject);begin  Exit;  With TEdit(Sender) do   Begin     SelStart := CaretPos.X;     SelLength := 0;   end;end;                         How's that? ---------------------------------------------------------------------- paweld · 2024-12-01 06:07 Quote from: jamie on December 01, 2024, 12:14:50 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Edit1Enter(Sender: TObject);begin  Exit;  With TEdit(Sender) do   Begin     SelStart := CaretPos.X;     SelLength := 0;   end;end;                           @jamie: anything after exit will not be executed ---------------------------------------------------------------------- jamie · 2024-12-01 11:48 Quote from: paweld on December 01, 2024, 07:07:37 amQuote from: jamie on December 01, 2024, 12:14:50 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Edit1Enter(Sender: TObject);begin  Exit;  With TEdit(Sender) do   Begin     SelStart := CaretPos.X;     SelLength := 0;   end;end;                           @jamie: anything after exit will not be executed U r correct. I pasted the wrong code. I placed the exit there as test and forgot to remove it for post. Shameful sin on my part