Board index » delphi » Selections in a TEdit (TPW)

Selections in a TEdit (TPW)

Hi,
  I have an edit box in a dialog, which I slave to a TEdit-derived object
using its InitResource method. What I observe is that if I load some text
into this edit box in the dialog's SetupWindow, this text is ALWAYS selected
when the box appears. I can't get rid of this selection! Any SetSelection
I perform in the dialog's SetupWindow is simply ignored. Furthermore, if
I have the following code:

procedure TMyDialog.SetupWindow;
begin
  Tdialog.SetupWindow;
  bla bla;
  Ebox^.SetText('Some text');
  EBox^.SetSelection(0,0);
  MessageBox(HWindow,'test','',mb_ok);
end;

Then the selection is OFF when the message box is displayed, but ON again
(and the cursor is at the end of the text) after the MessageBox terminates!

Whats going on? Who is setting the selection, and how do I get rid of it?

Thanks,
    Eyal Doron

 

Re:Selections in a TEdit (TPW)


Following up on my own post? Oh well.

Quote
Eyal Doron (do...@mickey.mpi-hd.mpg.de) wrote:

: Hi,
:   I have an edit box in a dialog, which I slave to a TEdit-derived object
: using its InitResource method. What I observe is that if I load some text
: into this edit box in the dialog's SetupWindow, this text is ALWAYS selected
: when the box appears. I can't get rid of this selection! Any SetSelection
: I perform in the dialog's SetupWindow is simply ignored:

: procedure TMyDialog.SetupWindow;
: begin
:   Tdialog.SetupWindow;
:   bla bla;
:   Ebox^.SetText('Some text');
:   EBox^.SetSelection(0,0);
: end;

: Whats going on? Who is setting the selection, and how do I get rid of it?

: Thanks,
:     Eyal Doron

Solution: replacing
   EBox^.SetSelection(0,0);
by
   PostMessage(EBox^.HWindow,em_SetSel,0,0);

Apparently this gets deferred to after dialog initialization.

Eyal Doron

Re:Selections in a TEdit (TPW)


In article <4pu80b$...@sun0.urz.uni-heidelberg.de>,
do...@mickey.mpi-hd.mpg.de (Eyal Doron) says:

Quote
>  I have an edit box in a dialog, which I slave to a TEdit-derived object
>using its InitResource method. What I observe is that if I load some text
>into this edit box in the dialog's SetupWindow, this text is ALWAYS selected
>when the box appears. I can't get rid of this selection! Any SetSelection
>I perform in the dialog's SetupWindow is simply ignored. Furthermore, if
>I have the following code:
>procedure TMyDialog.SetupWindow;
>begin
>  Tdialog.SetupWindow;
>  bla bla;
>  Ebox^.SetText('Some text');
>  EBox^.SetSelection(0,0);
>  MessageBox(HWindow,'test','',mb_ok);
>end;

When the edit control receives focus, the contents are selected.

Quote
>Then the selection is OFF when the message box is displayed, but ON again
>(and the cursor is at the end of the text) after the MessageBox terminates!

Note, that the selection is only displayed when the control has focus.
(Unless it is created with the style ES_NOHIDESEL)

Quote
>Whats going on? Who is setting the selection, and how do I get rid of it?

Try processing EN_SETFOCUS (sent to dlg).

-----------------------------------------------------------------------
  Zweitze de Vries                           zwei...@cyco.nl
  Cyco Software Development
  Handelskade 49
  Rijswijk, Netherlands                      (+31) 70 3954179

Other Threads