Recent

Author Topic: Hide Caret (TRichMemo, TKMemo)  (Read 5110 times)

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Hide Caret (TRichMemo, TKMemo)
« on: August 04, 2017, 10:50:36 am »
hi All,
cross-platform i am trying to hide the caret in a TRichMemo instance with no luck as per the below code.
please advise what i am missing.

thank you

Code: Pascal  [Select][+][-]
  1. type
  2.   TForm1 = class(TForm)
  3.     RichMemo1: TRichMemo;
  4.     procedure FormCreate(Sender: TObject);    
  5. ...
  6. procedure TForm1.FormCreate(Sender: TObject);
  7. var
  8.   p: TPoint;
  9. begin
  10.    p.x:= -1;
  11.    p.y:= -1;
  12.  
  13.    RichMemo1.Clear;
  14.    RichMemo1.ReadOnly:= true;
  15.    RichMemo1.CaretPos:= p;
  16. end;

« Last Edit: October 19, 2017, 12:18:30 pm by tudi_x »
Lazarus 2.0.2 64b on Debian LXDE 10

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: Hide Caret (TRichMemo, TKMemo)
« Reply #1 on: October 19, 2017, 12:19:41 pm »
Hi All,
how does one hide the caret in Memo controls (cross platform and with no other control to lose focus)? read only looks like not enough.
i see in Delphi there is a HideCaret(<control>) function.

thank you
« Last Edit: October 19, 2017, 01:06:27 pm by tudi_x »
Lazarus 2.0.2 64b on Debian LXDE 10

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: Hide Caret (TRichMemo, TKMemo)
« Reply #2 on: October 19, 2017, 01:43:11 pm »
looks like for TKMemo caret is not visible:
a. when the control does not have focus
b. when TKMemo.SelEnd < 0, safest:
Code: Pascal  [Select][+][-]
  1. TKMemo.SelEnd := -1;
  2. TKMemo.SelStart := 0;
« Last Edit: October 19, 2017, 01:53:55 pm by tudi_x »
Lazarus 2.0.2 64b on Debian LXDE 10

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Hide Caret (TRichMemo, TKMemo)
« Reply #3 on: October 19, 2017, 03:25:31 pm »
There are several ways to do this, this one is very easy, but don't ask me if this is a crossplatform way...  :)

Play around with this...
Code: Pascal  [Select][+][-]
  1. UNIT Unit1;
  2. {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes,  SysUtils, Forms, LCLIntf,
  7.   Controls, StdCtrls, LMessages;
  8.  
  9.  TYPE
  10.   TMyMemo = Class(TMemo)
  11.    PROTECTED
  12.     Procedure WMSetFocus (Var MSG: TLMessage); Message LM_SETFOCUS;
  13.   End;
  14.  
  15.  TYPE
  16.   TForm1 = Class(TForm)
  17.    Procedure FormCreate (Sender: TObject);
  18.     PRIVATE
  19.      Memo: TMyMemo;
  20.   End;
  21.  
  22.  VAR
  23.   Form1: TForm1;
  24.  
  25. Implementation
  26.  {$R *.LFM}
  27.  
  28.  
  29. Procedure TMyMemo.WMSetFocus(var MSG: TLMessage);
  30.  Begin
  31.   HideCaret(Handle);
  32.  End;
  33.  
  34.  
  35. Procedure TForm1.FormCreate(Sender: TObject);
  36.  Begin
  37.   Memo          := TMyMemo.Create(Self);
  38.   Memo.Align    := alClient;
  39.   Memo.Font.Size:= 20;
  40.   Memo.ReadOnly := True;
  41.   Memo.Text     := 'This is a test...';
  42.   Memo.Parent   := Self;
  43.  End;
  44.  
  45. END.
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: Hide Caret (TRichMemo, TKMemo)
« Reply #4 on: October 23, 2017, 10:48:55 am »
thank you RAW.
it does not work on Linux MINT.
looks like only TKMemo can be used cross platform.
Lazarus 2.0.2 64b on Debian LXDE 10

tk

  • Sr. Member
  • ****
  • Posts: 361
Re: Hide Caret (TRichMemo, TKMemo)
« Reply #5 on: November 07, 2017, 08:58:55 pm »
In KMemo check/include eoDisableCaret option in TKMemo.Options.
This will just disable the caret from appearing on screen, other functionality (writing, selections) remains the same.

 

TinyPortal © 2005-2018