Solved

SelectAll on Controlenter through MouseClick

Posted on 2000-03-15
5
215 Views
Last Modified: 2010-04-04
Hi,

I use Delphi4

if you click (with mouse lButton) in a TCombobox's edit, you will see,
that the content will selected (if autoselect=true).

if you click in a TEdit (AutoSelect is true). nothing is selected and the
cursor is set near mouse-click position.

I want to have the same behaviour as in TComboBox. So I try to set
"OnEnter" of the TEdit to something like

procedure TForm1.ControlEnter(Sender: TObject);
begin
 if sender is tedit then
     with sender as Tedit do selectall;
end;

but this will not help...

How to get the text selected, if click to the TEdit?

(If you enter the TEdit with TAB or calling SetFocus, the Text will be selected.
Only if you use the mouse, it fails)

ANY idea?

nmm




0
Comment
Question by:nmm
5 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2621553
You can do this:

procedure TForm1.ControlEnter(Sender: TObject);
begin
 if sender is tedit then
   with sender as Tedit do
     begin
       SelStart := 0;
       SelLength := Length(Text);
     end;
end;

Cheers,

Raymond.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2622568
hi,

just use a mouseevent like

procedure TForm1.Edit1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (sender is TEdit) then
    TEdit(Sender).SelectAll;
end;


meikl
0
 

Author Comment

by:nmm
ID: 2624080
Thank you, but it does not work.
The mouseclick is used by Delphi (windows?) to set cursorpos *after*
processing OnEnter. So the selection is removed...

The solution from  kretzschmar
is also not good, because than the usual mouseclick inside does not set cursorpos.

I want: if you click *first* in the TEdit (onEnter), all sould be selected, but if you click again it should behave "normal".
Just like TComboBox.

nmm
0
 
LVL 4

Accepted Solution

by:
DMN earned 100 total points
ID: 2634565
The code below works perfect for me:

interface

const
  CM_SELECTALL = WM_USER+333;

type
  TsaEdit = class(TEdit)
  private
    { Private declarations }
    procedure CMEnter(var Message:TMessage); message CM_ENTER;
    procedure CMSelectAll(var Message:TMessage); message CM_SELECTALL;
  protected
    { Protected declarations }
  public
    { Public declarations }
  published
    { Published declarations }
  end;

implementation

procedure TsaEdit.CMEnter;
begin
  inherited;
  if AutoSelect then
    PostMessage(Handle, CM_SELECTALL,0,0);
end;

procedure TsaEdit.CMSelectAll;
begin
  SelectAll;
  inherited;
end;
0
 

Author Comment

by:nmm
ID: 2635237
Thank you DMN, it works and is just I need!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question