Board index » cppbuilder » SelectAll does not seem to work in the OnEnter event for a TEdit field

SelectAll does not seem to work in the OnEnter event for a TEdit field

I have the following event handler assigned to the OnEnter event
of a TEdit field with the name efield.  This should select the
text in the field when the field is entered, but it does not.

void __fastcall TForm::efieldEnter(TObject *Sender)
{
    efield->SelectAll();

Quote
}

Can someone help?
 

Re:SelectAll does not seem to work in the OnEnter event for a TEdit field


Quote
Richard Casten wrote:
> I have the following event handler assigned to the OnEnter
> event of a TEdit field with the name efield.  This should select
> the text in the field when the field is entered, but it does not.

Try this instead:

void __fastcall TForm::efieldEnter(TObject *Sender)
 {
     PostMessage(efield->Handle, EM_SETSEL, 0, -1);
 }

Re:SelectAll does not seem to work in the OnEnter event for a TEdit field


Thanks.  That worked.  However, I would like to know why the SelectAll
method does not since the documentation implies that it should.  In
fact, if you use the SelectAll method for an OnClick event it does
work.
Quote
Fishface wrote:
> Richard Casten wrote:
> > I have the following event handler assigned to the OnEnter
> > event of a TEdit field with the name efield.  This should select
> > the text in the field when the field is entered, but it does not.

> Try this instead:

> void __fastcall TForm::efieldEnter(TObject *Sender)
>  {
>      PostMessage(efield->Handle, EM_SETSEL, 0, -1);
>  }

Re:SelectAll does not seem to work in the OnEnter event for a TEdit field


Quote
Richard Casten wrote:
> That worked.  However, I would like to know why the SelectAll
> method does not since the documentation implies that it should.  In
> fact, if you use the SelectAll method for an OnClick event it does
> work.

I think it does work, for about a microsecond, until it receives that
WM_LBUTTONDOWN message...

Re:SelectAll does not seem to work in the OnEnter event for a TEdit field


Brent, you were right on. When I use SendMessage it does not work.  Thanks!
Quote
Brent wrote:
> Hi Richard,

> Cant say for certain, but FishFace posted code that was Synchronous, whereas
> the VCL may have used ASynchronous code to select the text.  For further
> examination, you could try SendMessage instead of PostMessage to see if my
> theory is valid.

> HTH,    Brent

> Richard Casten <richard.cas...@aero.org> wrote in message
> news:3A101D07.809D7C1F@aero.org...
> > Thanks.  That worked.  However, I would like to know why the SelectAll
> > method does not since the documentation implies that it should.  In
> > fact, if you use the SelectAll method for an OnClick event it does
> > work.

> > Fishface wrote:

> > > Richard Casten wrote:
> > > > I have the following event handler assigned to the OnEnter
> > > > event of a TEdit field with the name efield.  This should select
> > > > the text in the field when the field is entered, but it does not.

> > > Try this instead:

> > > void __fastcall TForm::efieldEnter(TObject *Sender)
> > >  {
> > >      PostMessage(efield->Handle, EM_SETSEL, 0, -1);
> > >  }

Re:SelectAll does not seem to work in the OnEnter event for a TEdit field


Hi Richard,

Cant say for certain, but FishFace posted code that was Synchronous, whereas
the VCL may have used ASynchronous code to select the text.  For further
examination, you could try SendMessage instead of PostMessage to see if my
theory is valid.

HTH,    Brent

Quote
Richard Casten <richard.cas...@aero.org> wrote in message

news:3A101D07.809D7C1F@aero.org...
Quote
> Thanks.  That worked.  However, I would like to know why the SelectAll
> method does not since the documentation implies that it should.  In
> fact, if you use the SelectAll method for an OnClick event it does
> work.

> Fishface wrote:

> > Richard Casten wrote:
> > > I have the following event handler assigned to the OnEnter
> > > event of a TEdit field with the name efield.  This should select
> > > the text in the field when the field is entered, but it does not.

> > Try this instead:

> > void __fastcall TForm::efieldEnter(TObject *Sender)
> >  {
> >      PostMessage(efield->Handle, EM_SETSEL, 0, -1);
> >  }

Other Threads