How to prevent text to be selected in tedit? lazarus / 21-General ---------------------------------------------------------------------- Ramses · 2021-03-05 13:46 Hi! I have a tedit that i use to show information, and i dont want the user to be able to select/copy text in it, is there an easy way to do that without disabled it (because the disable function gray out the text)? Or maybe its more easier to replace the tedit by a label? Thanks ---------------------------------------------------------------------- ASerge · 2021-03-05 13:48 Quote from: Ramses on March 05, 2021, 02:46:20 pmOr maybe its more easier to replace the tedit by a label? Yes ---------------------------------------------------------------------- Ramses · 2021-03-05 14:13 alright, i was thinking that there was an option somewhere to do that, but if there is no easy way to do that i will replace every tedit with labels.. thanks for yiour answer ---------------------------------------------------------------------- winni · 2021-03-05 16:11 Hi! If you prefer TEdit: It has a property ReadOnly. Setting this to true is disabling any changes. Winni ---------------------------------------------------------------------- Ramses · 2021-03-05 16:54 Quote from: winni on March 05, 2021, 05:11:34 pmHi! If you prefer TEdit: It has a property ReadOnly. Setting this to true is disabling any changes. Winni read only prevent any change but dont prevent from select/copy text, so i used the label instead ---------------------------------------------------------------------- Warfley · 2021-03-05 17:09 Also possible, disable the edit, this will "gray it out" 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 MyEdit.Enabled := False;But it will also disable all events and possibly (I don't know right now) also disable updating the control, so you might need to temporary enable it to write stuff into it ---------------------------------------------------------------------- winni · 2021-03-05 17:24 Quote from: Warfley on March 05, 2021, 06:09:36 pmAlso possible, disable the edit, this will "gray it out" 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 MyEdit.Enabled := False;But it will also disable all events and possibly (I don't know right now) also disable updating the control, so you might need to temporary enable it to write stuff into it He does not want that! Try to read again! ---------------------------------------------------------------------- wp · 2021-03-05 18:19 Could not yet find a way to prevent selecting by a double-click, but when you catch the keyboard events, at least OnKeyDown, and disable it (Key := 0) then the user cannot enter anything any more. Also pasting from the clipboard by pressing CTRL+V is disable this way.  You could also disable selecting by dragging the mouse when you call Abort in the OnMouseMove event: 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.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );begin  Key := 0;end; procedure TForm1.Edit1Click(Sender: TObject);begin  Abort;end; procedure TForm1.Edit1MouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);begin  Abort;end; ---------------------------------------------------------------------- Bart · 2021-03-05 19:13 Quote from: wp on March 05, 2021, 07:19:08 pmCould not yet find a way to prevent selecting by a double-click, On double click set SelLength to zero? All this of course is a hack. Bart ---------------------------------------------------------------------- wp · 2021-03-05 20:58 Yes, I thought if that. But the selection goes away and comes back again. Strange... ---------------------------------------------------------------------- jamie · 2021-03-05 22:46 This may work cross platform wise, I can't say but anyways, this will reject a copy paste operation. It may look and feel like its taking place but it gets rejected..  Also you can replace the popup menu for the edit with a dummy one, that way the system's menu does not come up either.. I can't say if this works well in Lazarus across the board but it something I've done in Delphi... You need to set the variable to TRUE to reject the operation... otherwise it behaves normally.. This only works per unit/Form page.. of course.. 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 unit Unit1; {$mode objfpc}{$H+} interface uses  Windows,Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }TEDIT = Class(stdCtrls.TEDIT)  procedure HandlePaste(Var Msg:TMessage); Message WM_Paste;  procedure HandleCopy(Var Msg:TMessage); Message WM_Copy;  Public   RejectClipBoardOperations:Boolean;end;   TForm1 = class(TForm)    Edit1: TEdit;  private   public  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 }Procedure TEdit.HandleCopy(Var msg:TMessage);Begin  if rejectClipBoardOperations Then     Msg.Result := 1 else Inherited;end; Procedure TEdit.HandlePaste(Var Msg:TMessage);Begin  If rejectClipboardOperations Then            Msg.Result := 1 Else Inherited;end; end.   Don't forget to set the variable at runtime somewhere on the EDITS you want this behavior.. ---------------------------------------------------------------------- CM630 · 2025-07-15 08:59 Trying to disable Double Cick selection in a custom control.   MyEdit = class(TCustomEdit) Is it possible? ---------------------------------------------------------------------- Thaddy · 2025-07-15 09:45 Yes.  Set Enabled to false . ---------------------------------------------------------------------- CM630 · 2025-07-15 11:34 I need it to be editable and selectable. I need to disable only the double/triple click selection. ---------------------------------------------------------------------- Thaddy · 2025-07-15 11:49 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.Memo1DblClick(Sender: TObject);begin  memo1.SelLength:=0;end; procedure TForm1.Edit1DblClick(Sender: TObject);begin  edit1.SelLength:=0;end; Selection is still possible with the mouse, as is right click. If doubleclick is disabled like so, triple click is also disabled. Is that enough? It is probably not perfect. ---------------------------------------------------------------------- CM630 · 2025-07-15 12:37 It is rather that I did not explain what I need. memo1.SelLength:=0; will still change the selection, I need it unchanged. I rather need to prevent Double Click from making any changes. I can store the previous selection values in variable, and when a double click occurs to restore them somehow. If there is no native solution, that is what I will try to do. ---------------------------------------------------------------------- Thaddy · 2025-07-15 13:36 Replace memo1.sellenght := 0 with Exit? [edit] or add it? ---------------------------------------------------------------------- CM630 · 2025-07-15 15:13 I think/guess the problem is that TEdit internally handles double click as select word and (probably) tripple click as select the entire content of the line. So using TCustomEdit will lead me nowhere, even if I override the OnClick event. Maybe I could use some non-OS widget, possibly a BGRA control or something similar. Quote from: CM630 on July 15, 2025, 02:37:57 pm... I can store the previous selection values in variable, and when a double click occurs to restore them somehow. If there is no native solution, that is what I will try to do. I tried that, it works, but it seems bad - the entire text is selected for a while and then the selection returns to where it should be.