Solved

SelectAll on Controlenter through MouseClick

Posted on 2000-03-15
5
211 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 88
Virtuailstring tree compare node issue 14 116
FMX enumerated colours 2 97
How to debug For loops? 3 49
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

816 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now