Selecting words in TEdit-like components. lazarus / 31-LCL ---------------------------------------------------------------------- agb · 2012-09-02 20:23 Hi, All! First, I will describe problem: We have a string in edit control (TEdit, TDBEdit, TMemo etc.), we want select one word. Two ways is present: 1) Double Click on it 2) Put Text caret in beginning of word and press Ctrl+Shift+ArrowLeft Problem: In all cases will be selected word with trailing spaces, dots, commas etc. I can not find any code in sources witch is handle key combinations for quick select. Will be fine to fix this on most low level. Can anybody show me this place in libruary? Also will be cool to make TripleClick to select all text in edit (or in TDBGrid cell) control  (like Ctrl+A). ---------------------------------------------------------------------- Blaazen · 2012-09-02 21:02 TEdit has properties and methods: Code: [Select]Edit1.SelStart:=3; Edit1.SelLength:=4; MyString:=Edit1.SelText; Edit1.SelectAll;    For removing trailing spaces there's function trim(). AFAIK there is no special function for removing ,.;: so you will have to put the string to "for .. in" loop and check it. ---------------------------------------------------------------------- User137 · 2012-09-02 22:37 Quote from: Blaazen on September 02, 2012, 11:02:33 pmAFAIK there is no special function for removing ,.;: so you will have to put the string to "for .. in" loop and check it.There is StringReplace http://www.freepascal.org/docs-html/rtl/sysutils/stringreplace.html But i'm not sure if it's of use to this problem. If you are looking for position after each commas and so on, i guess you just have to do manual for-loop, and check if character is in set [",", ".", " "]. Keep searching until character doesn't match those. ---------------------------------------------------------------------- agb · 2012-09-03 06:52 I know, how to get selection result and clean it. But I want change component's behavior for double-clicking. Component should not select trailing spaces and commas. Like in OpenOffice Writer: Doubleclick on word - only word selected, Three-click - one sentence. I can not find any code (in TComponent, TWinControl, TControl, TCusomEdit) doing selection in control on doubleclick. ---------------------------------------------------------------------- Blaazen · 2012-09-03 09:17 QuoteI can not find any code (in TComponent, TWinControl, TControl, TCusomEdit) doing selection in control on doubleclick. Maybe there's no such code. Lazarus uses underlaying widgetset, OpenOffice doesn't. I use LCL+Qt, so, in fact, TEdit is probably QEdit here. Maybe you will find such code for TMemo. Maybe you can derive your own component from TEdit and override some DblClick; method. You will have to try. ---------------------------------------------------------------------- KpjComp · 2012-09-03 10:57 You could try something like this -> Code: [Select]procedure TForm1.Edit1DblClick(Sender: TObject); var   edit:TEdit;   txt:string;   epos,newlen:integer; begin   edit := Sender as TEdit;   txt := edit.Text;   newlen := Edit.SelLength;   epos := Edit.SelStart+newLen;   while not (txt[epos] in ['A'..'Z','a'..'z']) do   begin     if epos < 1 then break;     dec(epos);     dec(NewLen);   end;   Edit.SelLength := NewLen; end;  You could of course make it include numbers, etc by changing the in [] bit.