?
Solved

SelectAll on Controlenter through MouseClick

Posted on 2000-03-15
5
Medium Priority
?
221 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

771 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