Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SelectAll on Controlenter through MouseClick

Posted on 2000-03-15
5
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

598 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