Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

Hide caret (text cursor) "inside" TMemo component

By Zarko Gajic, About.com

Here's a sample code showing how to hide the caret in Memo1 (TMemo) component on Form1 (TForm).

Go to Code Window, select all, and replace with the code below...

~~~~~~~~~~~~~~~~~~~~~~~~~
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls;

  const
    WM_MYMEMO_ENTER = WM_USER + 500;

  type
    TForm1 = class(TForm)
      Memo1: TMemo;
      procedure Memo1Enter(Sender: TObject) ;
      procedure Memo1Exit(Sender: TObject) ;
      procedure Memo1Change(Sender: TObject) ;
    private
    public
      procedure WMMYMEMOENTER(var Message: TMessage) ;
                message WM_MYMEMO_ENTER;
    end;

var Form1: TForm1;

implementation
{$R *.DFM}

procedure TForm1.WMMYMEMOENTER(var Message: TMessage) ;
begin
   CreateCaret(Memo1.Handle,0,0,0) ;
end;

procedure TForm1.Memo1Enter(Sender: TObject) ;
begin
   PostMessage(Handle, WM_MYMEMO_ENTER, 0, 0) ;
end;

procedure TForm1.Memo1Exit(Sender: TObject) ;
begin
   CreateCaret(Memo1.handle,1,1,1) ;
end;

procedure TForm1.MemoChange(Sender: TObject) ;
begin
   CreateCaret(Memo1.handle,0,0,0) ;
end;
end.
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to search and replace in RichEdit
« How to merge strings in two TStringList's

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TMemo, TRichEdit
  6. Hide caret (text cursor) "inside" TMemo component

©2009 About.com, a part of The New York Times Company.

All rights reserved.