Solved

SelectAll on Controlenter through MouseClick

Posted on 2000-03-15
5
206 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you DMN, it works and is just I need!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

762 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

10 Experts available now in Live!

Get 1:1 Help Now